5

Say I have a document of type

\documentclass{article}
\usepackeage{hyperref}

%\includeonly{Chap1}
%\includeonly{Chap2}

\begin{document}

\include{Chap1}
\include{Chap2}

\end{document}

Where Chap1 \ref's labels of Chap2 and vice versa. Using \includeonly, I want to compile Chap1 to Chap1.pdf and Chap2 to Chap2.pdf.

Is there a way to inform hyperref about this, so a reference Chap2.pdf will automatically be hyperlinked so that it opens the referenced location in Chap1.pdf ?

1
  • The instructions for the xr-hyper package are the same as for the xr package. I'll post a quick answer to explain its functioning.
    – Mico
    Apr 14, 2014 at 23:28

1 Answer 1

4

If I understand your setup correctly, you have two separate standalone documents, say, doca.tex and docb.tex, and you'd like to cross-reference an item (e.g., a chapter) from Document A in Document B.

One way to achieve this objective is to use the xr-hyper package, which is part of the hyperref bundle. The xr-hyper pacakge works exactly like the xr package. E.g., suppose doca.tex consists of the following code:

%% doca.tex
\documentclass{report}
\usepackage{hyperref,xr-hyper}
\begin{document}
\chapter{Beginning of Doc A} \label{doca:chap:1}
In the beginning, \dots
\end{document}

Note that both the hyperref and xr-hyper packages are loaded. Compile it twice and make sure not to delete the file doca.aux as it contains important cross-referencing information.

Suppose further that docb.tex contains the following code:

\documentclass{report}
\usepackage[colorlinks=true]{hyperref}
\usepackage{xr-hyper}
\externaldocument{doca}
\begin{document}
\chapter{End of Doc B} 
As we argued in \autoref{doca:chap:1} of Document A, \dots
\end{document}

The crucial extra instruction is \externaldocument{doca}: it tells LaTeX to search in doca.aux for labels to cross-references. The directive \autoref{doca:chap:1} will then successfully create a cross-reference to "chapter 1" of Document A.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .