2

I want to compile a large series of mostly independent latex files into a single document, and I would like to be able to assume that each \label lives in its own "namespace". Ideally, what I would like to have is:

file1.tex:

\begin{equation}
  \label{eq:a}
  a+b
\end{equation}

This is \eqref{eq:a}

file2.tex:

\begin{equation}
  \label{eq:a}
  a+2b
\end{equation}

This is a very different \eqref{eq:a}

main.tex:

\include{file1.tex}
\include{file2.tex}

I would like to reference (with hyperref) both \ref{eq:a@file1.tex} and \ref{eq:a@file2.tex}

The purpose of this is to cross-reference and assemble a large collection of independent documents (but not to spend days doing so).

A solution in which the cross-referencing would work across multiple PDF file would suit me too, but I fear it would be a lot harder.

  • 1
    To prefix the labels from other files in a "central" file you could use the xr or xr-hyper package. To include the independent files, I suggest to compile them separately and include the pdfs – user36296 Jul 11 '17 at 15:02
  • @samcarter seems like a starting point, I'll have to dig into that more. The xr documentation is, hmm, terse – Vincent Fourmond Jul 11 '17 at 15:16
2

For example with document.tex:

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\begin{equation}
  \label{eq:a}
  a+2b
\end{equation}

This is a very different \ref{eq:a}

\end{document}

you could reference the label with a prefix using the xr package (or xr-hyper if combined with hyperref)

\documentclass{article}

\usepackage{xr-hyper}
\usepackage{hyperref}

\externaldocument[doc-]{document}

\usepackage{pdfpages}

\begin{document}

\includepdf[xr-prefix=doc-]{document}


bla \ref{doc-eq:a}

\end{document}

(the option xr-prefix is an experimental option of pdfpages)

  • 1
    The link targets the original PDF file (not the one included), but this is exactly what I'm looking for, thanks ! – Vincent Fourmond Jul 11 '17 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.