Welcome to the UK List of
TeX Frequently Asked Questions
on the Web

Searching

The index of Frequently Asked Questions about TeX is searchable.

Please enter your keyword here:   then press here: ,    or:
Google

Referring to labels in other documents

When producing a set of inter-related documents, you’ll often want to refer to labels in another document of the set; but LaTeX, of its own accord, doesn’t permit this.

So the package xr was written: if you say

\usepackage{xr}
\externaldocument{volume1}

will load all the references from volume1 into your present document.

But what if the documents both have a section labelled “introduction” (likely enough, after all)? The package provides a means to transform all the imported labels, so you don’t have to change label names in either document. For example:

\usepackage{xr}
\externaldocument[V1-]{volume1}

loads the references from volume1, but prefixes every one with the string V1-. So you would refer to the introduction to volume 1 as:

\usepackage{xr}
\externaldocument[V1-]{volume1}
...
... the introduction to volume1 (\ref{V1-introduction})...

To have the facilities of xr working with hyperref, you need xr-hyper. For simple hyper-cross-referencing (i.e., to a local PDF file you’ve just compiled), write:

\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[V1-]{volume1}
...
... the \nameref{V1-introduction})...

and the name reference will appear as an active link to the “introduction” chapter of volume1.pdf.

To link to a PDF document on the Web, for which you happen to have the .aux file, write:

\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[V1-]{volume1}[http://mybook.com/volume1.pdf]
...
... the \nameref{V1-introduction})...

Heiko Oberdiek’s experimental zref bundle includes a hyper-crossreferencing mechanism using its zref-xr module. Usage is closely modelled on xr and xr-hyper; a trivial example (from a comp.text.tex posting) is

\usepackage{zref-xr,zref-user}
\zexternaldocument*{xr02}
...
\zref{foo}

The module provides all the facilities of the older packages, and can deal both with “traditional” LaTeX labels and with zref’s style of labels.

xr.sty
Distributed as part of macros/latex/required/tools (or browse the directory); catalogue entry
xr-hyper.sty
Distributed with macros/latex/contrib/hyperref (or browse the directory); catalogue entry
zref bundle
Distributed as part of macros/latex/contrib/oberdiek (or browse the directory); catalogue entry


Go to previous question, or next question

Go to FAQ home.

URL for this question: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=extref

Comments, suggestions, or error reports? - see “how to improve the FAQ”.

This is FAQ version 3.27, released on 2013-06-07.