Previous: , Up: Cross references   [Contents][Index]

### 7.4 xr package

Synopsis:

\usepackage{xr}
\externaldocument{document-basename}


or

\usepackage{xr}
\externaldocument[reference-prefix]{document-basename}


Make cross references to the external document document-basename.tex.

Here is an example. If lectures.tex has this in the preamble

\usepackage{xr}
\externaldocument{exercises}
\externaldocument[H-]{hints}


then it can use cross reference labels from the other three documents. Suppose that exercises.tex has an enumerated list containing this,

\item \label{exer:EulersThm} What if every vertex has odd degree?


and hints.tex has an enumerated list with this,

\item \label{exer:EulersThm} Distinguish the case of two vertices.


and answers.tex has an enumerated list with this,

\item \label{ans:EulersThm} There is no Euler path, except if there
are exactly two vertices.


After compiling the exercises, hints, and answers documents, entering this in the body of lectures.tex will result in the lectures getting the reference numbers used in the other documents.

See Exercise~\ref{exer:EulersThm}, with Hint~\ref{H-exer:EulersThm}.


The prefix H- for the reference from the hints file is needed because the label in the hints file is the same as the label in the exercises file. Without that prefix, both references would get the number from the later file.

Note: if the document uses the hyperref package then in place of xr, put \usepackage{xr-hyper} before the \usepackage{hyperref}. Also, if any of the multiple documents uses hyperref then they all must use it.