[Tex/LaTex] Does hyperref work between two files

cross-referencinghyperref

Can I create a link from one file into another one. So that when the resulting pdf files are in the same directory the link takes me from one to the other? Does another package do that?

Added on 1/20/2012, Reason for the question: I want to submit a document to an organization which wants it to be split into A.pdf for body of paper and B.pdf for the references, C.pdf etc. I assume they will reside in a common directory. They may be viewed individually or coalesced together into a single document.

Best Answer

Just to give a full example. I have found xr-hyper quite tricky to get it to work. It seems that xr-hyper must be called before hyperref and both documents must be compiled twice. Below is an example that shows how to get it going.

  1. write the following two tex file, docA.tex and docB.tex
  2. put both files in the same directory, otherwise the path must be specified as part of the xr header.
  3. run pdfLaTeX twice on both filles. First on docA and then on docB and repeat the process

EDIT2: I do not think citations will work accross files (not natbib at least)

docA.tex

\documentclass{article} 
\usepackage{xr-hyper} 
\usepackage{hyperref} 
\externaldocument[B-]{docB}[docB.pdf]% <- full or relative path 
\begin{document}
    This is a test for math.
    \begin{equation}
        E=mc^2 \label{eq:1}
    \end{equation}
    This is a second test for math.
    \begin{equation}
        r = \sqrt{x^2 + y^2} \label{eq:2}
    \end{equation}
    In document B Eq.~~(\ref{B-eq:x}) 
\end{document}

docB.tex

\documentclass{article}
\usepackage{xr-hyper}
\usepackage{hyperref}
\externaldocument[A-]{docA}[docA.pdf]% <- full or relative path
\begin{document}
  \setcounter{equation}{5}

  As was shown in Eq.~(\ref{A-eq:1}) is it
  ... or in Eq.~(\ref{A-eq:2}) is ...
  \begin{equation}
    \mathrm{e}^{i\pi}-1=0 \label{eq:x}
  \end{equation}
\end{document}
Related Question