My document structure is basically a collection of other smaller documents. I decided not to go down the xr-hyper road and having individual PDF documents, because the requirement in the end is a single file anyway. So, instead, I decided to create one big LaTeX document with my sub-documents as books, e.g.:
\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}
Now this As shown in \ref{chap:maindoc-first}
will render as if the chapter was in the scope of the current part. What I'd like to accomplish is something like:
- As shown in chapter 1 of the maindoc and chapter 1...
- As shown in chapter 1 (maindoc) and chapter 1 ...
- As shown in (1, maindoc) and (1) ...
- As shown in A-1 and 1 ...
However, as most references are within the documents themselves, I don't want to prefix all of the references as in this Q&A.
How can I accomplish this? Is there a way to determine the scope of the reference and include the prefix conditionally?
Ultimately, I'd like to do the same for references to theorems, figures, tables, etc.