%3F.png)
私の文書構造は、基本的に他の小さな文書の集合体です。xr-ハイパー結局は1つのファイルで済むので、個別のPDF文書を作成するのは面倒です。そこで、代わりにサブ文書を1つの大きなLaTeX文書にまとめることにしました。本例:
\documentclass{memoir}
\renewcommand*{\thebook}{\Alph{book}} % "Book A", "Book B", etc.
\begin{document}
\book{maindoc}
\chapter{maindoc first chapter}
\label{chap:maindoc-first}
\chapter{maindoc second chapter}
\label{chap:maindoc-second}
\book{extradoc}
\setcounter{chapter}{0} % reset chapter counter with each book
\chapter{extradoc first chapter}
\label{chap:extradoc-first}
\chapter{extradoc second chapter}
\label{chap:extradoc-second}
As shown in \ref{chap:maindoc-first}, and further research in \ref{chap:extradoc-first} ...
\book{anotherdoc}
\setcounter{chapter}{0}
\chapter{anotherdoc chapter}
\end{document}
これで、As shown in \ref{chap:maindoc-first}
その章が現在のパートの範囲内にあるかのようにレンダリングされます。私が実現したいのは次のようなものです。
- メインドキュメントの第 1 章と第 1 章に示されているように...
- 第 1 章 (maindoc) および第 1 章に示されているように...
- (1, maindoc) および (1) に示されているように...
- A-1、1に示すように…
しかし、ほとんどの参照は文書自体の中にあるので、全て参照文献のこのQ&A。
これを実現するにはどうすればよいですか? 参照の範囲を決定し、条件付きでプレフィックスを含める方法はありますか?
最終的には、定理、図、表などの参照についても同じことをしたいと思います。
答え1
を使用しているのでmemoir
、クラスが提供する相互参照機能を活用する必要があります。これは、ユーザーマニュアル。
memoir
ただし、 は書式設定に関してかなり明確な考え方を持っているため、その考え方を超える柔軟性を常に提供しているわけではありません。 この場合、 は文書の他の部分への相互参照は大文字にすべきであると考えています。 これを避けたい場合は、代替手段を提供する必要があります。
以下は、 が提供するバージョンに基づいていますmemoir
。
\aref% based on \Aref
\bref% \Bref
\cref% \Cref
\sref% \Sref
小文字の名前は以下によって提供されます:
\lcbookrefname% based on \bookrefname
\lcchapterrefname% \chapterrefname
\lcsectionrefname% identical to \sectionrefname
\lcappendixrefname% based on \appendixrefname
\titleref
これにより、 が提供するコマンドと組み合わせることで、必要に応じて参照を設定できますmemoir
。
これを自動化するために、\chapref{}
最初にリストした可能性に従ってフォーマットされた参照を生成するコマンドが提供されています。同様の方法で他の形式を実現する他のコマンドを作成することもできます。
注記:\chapref
少なくとも、私がコマンドをコーディングした方法は、最善の方法ではないのではないかと思います。買い手責任負担...
\documentclass{memoir}
\renewcommand*{\thebook}{\Alph{book}} % "Book A", "Book B", etc.
\newcommand*{\aref}[1]{\lcappendixrefname\ref{#1}}
\newcommand*{\bref}[1]{\lcbookrefname\ref{#1}}
\newcommand*{\cref}[1]{\lcchapterrefname\ref{#1}}
\newcommand*{\sref}[1]{\lcsectionrefname\ref{#1}}
\newcommand*{\lcbookrefname}{book~}
\newcommand*{\lcchapterrefname}{chapter~}
\newcommand*{\lcsectionrefname}{\S}
\newcommand*{\lcappendixrefname}{appendix~}
\makeatletter
\def\chapref@book#1:#2-#3\@nil{#2}
\newcommand*{\chapref}[1]{%
\edef\tempa{\expandafter\chapref@book#1\@nil}%
\edef\tempb{\ref{book:\tempa}}%
\edef\tempc{\thebook}%
\ifx\tempb\tempc
\cref{#1}%
\else
\cref{#1} of the \titleref{book:\tempa}%
\fi}
\makeatother
\begin{document}
\book{maindoc}
\label{book:maindoc}
\chapter{maindoc first chapter}
\label{chap:maindoc-first}
\chapter{maindoc second chapter}
\label{chap:maindoc-second}
\book{extradoc}
\label{book:extradoc}
\setcounter{chapter}{0} % reset chapter counter with each book
\chapter{extradoc first chapter}
\label{chap:extradoc-first}
\chapter{extradoc second chapter}
\label{chap:extradoc-second}
Manually using the facilities of the class:
As shown in \cref{chap:maindoc-first} of the \titleref{book:maindoc}, and further research in \cref{chap:extradoc-first} ...
\noindent Or using the custom command:
As shown in \chapref{chap:maindoc-first}, and further research in \chapref{chap:extradoc-first} \dots
\book{anotherdoc}
\setcounter{chapter}{0}
\chapter{anotherdoc chapter}
\end{document}