Cross-referencing between different files
You can use the xr
package to reference to other LaTeX document.
So in chapterII.tex
you say:
\usepackage{xr}
\externaldocument{chapterI}
And then can use \ref{a}
like normal.
You can also add a prefix:
\externaldocument[I-]{chapterI}
then you can reference it as \ref{I-a}
which is useful if you have identical label names in different chapters.
Note that the normal xr
doesn't add hyperlinks. It only adds the label text. The zref
package can be used for this. It provides the zref-xr
subpackage which gives you the same functionality and should work fine with hyperref
(after all both packages are from the same author).
You only need to replace \externaldocument
with \zexternaldocument
as well as \ref
with \zref
.
Note that the xr
package reads the aux
file, e.g. in this case, it checks chapterI.aux
for references.
Beamer and xr: If you want to use the xr
package to pull external references into a Beamer document, you need to be sure that the source of the references has been typeset using the hyperref
package. This is because Beamer uses hyperref by default and the format of the references in the .aux file is different for hyperref
. If the references are coming from another Beamer document, there is no need to do anything. If they are coming from a basic LaTeX document you may need to add \usepackage{hyperref}
and typeset the source document again. As far as I can tell, there is no downside to always using hyperref
.
This FAQ from the UK TUG suggests to use xr-hyper
if using hyperref
:
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[V1-]{volume1} % Not volume1.tex
...
... (see Volume~I, Section~\ref{V1-sIntroduction}) ...
The FAQ cites zref-xr
as a superset.
Dear users of zref
: please edit this answer to list some benefits of zref
.