Open gardners opened 3 years ago
Looks like my addition of the following does the trick:
% Allow cross-references between the various books to the big The MEGA65 Book
\usepackage{xr}
\externaldocument[M65Book-]{mega65-book}
% And a \ref alternative that checks if it needs to be a cross-reference to the
% MEGA65 Book instead.
\makeatletter
\newcommand{\bookref}[1]{%
\@ifundefined{r@#1}{%
{\em the MEGA65 Book}, \nameref{M65Book-#1}, (Chapter or Appendix \ref{M65Book-#1})
}{\ref{#1}}%
}
\newcommand{\bookvref}[1]{%
\@ifundefined{r@#1}{%
{\em the MEGA65 Book}, \nameref{M65Book-#1}, (Chapter or Appendix \ref{M65Book-#1})
}{\vref{#1}}%
}
\makeatother
Basically use \bookref and \bookvref instead of \ref and \vref now, and it will automatically refer to the internal reference if present, else to the appropriate named chapter or section in The MEGA65 Book.
I might leave the chapter number out, since that is most prone to changing.
Now it would be good to detect if the reference is a chapter or appendix, so that we can tighten up the language. Basically if the referenced chapter number is letter, its an appendix, else its a chapter.
We use some of the same chapters in multiple books, in particular, "The MEGA65 Book" contains all of the chapters from all of the other books, so that there is a single comprehensive PDF for ease of desk searching.
In some chapters we reference material that may or may not be in the various books in which they appear. When the material is NOT in the same book, then we need a way to reference it in the other books in which it appears.
We could add The MEGA65 Book as an external document using the xr package, and then refer to that.
But ideally we would only do that, if the label is not already defined in the current document. This would mean we need a macro that does \ref{foo} if \label{foo} is defined, or otherwise does something like \ref{M65Book-foo} if it is not defined.
In the meantime, we get undefined references for those