10

I have a big report with appendices. Now I would like to put my appendices in a separate file. That's no problem at all. But I refer to my appendices in my main file. What would be the easiest way to refer to my appendices in my main file, while the appendices themselves are separate?

Right now I have my appendices both in my main file and a separate appendices file and made sure the page numbering is the same. But now I have my appendices in my main file while I dont need them there.

Is there some easier way to do this?

Short version: is there some easy way to crossrefer to another latex file?

Alan Munn
  • 218,180
Elmer
  • 2,254
  • User the xr package (or xr-hyper), have a look at How to reference another document in LaTeX. If the answer there can already help you, we could close this question as a duplicate with link to that answer. – Stefan Kottwitz Apr 17 '11 at 14:39
  • Reading both the links u gave me, gimme a minute to see if that covers my question. – Elmer Apr 17 '11 at 14:45
  • I took a look at the xr and xr-hyper packages. There aint too much documentation on it. They seem to assume both latex files are in the same folder. Would it be possible also to refer to a file in a complete different folder? – Elmer Apr 17 '11 at 14:51
  • 1
    Maybe what you want to do is better served with \include/\includeonly. See When should I use \input vs \include ? for more information on this. – Alan Munn Apr 17 '11 at 15:25
  • @Alan Munn how could i solve my problem/question using \include and \includeonly then? – Elmer Apr 17 '11 at 18:05
  • @Elmer the idea is that you keep your appendices as separate files, but you use \include to include them in your source. This keeps your source documents manageable, but the whole document behaves as a single document from the point of view of cross-references. – Alan Munn Apr 17 '11 at 18:36
  • @Alan Munn I already do so, i have 1 main file, and use \include to include them in my mainfile. But with my seperate appendices, i have 2 "mainfiles". – Elmer Apr 17 '11 at 19:55
  • @Elmer Then I guess I don't understand your problem anymore. Suppose I have a main.tex plus chap1.tex, chap2.tex, app1.tex, app2.tex etc. and use \include to include the chapters. How is that the same as having more than one main file? – Alan Munn Apr 17 '11 at 19:59
  • @Alan Munn Its not the same. I have 2 main files. I use main1 to indlude my chapters. Main2 is used to include my appendices.

    now the question is, what the easiest way is, to refer to my appendices in main1.

    hope u understand what i mean now. Excuse my english.

    – Elmer Apr 17 '11 at 20:20
  • @Elmer: I believe Alan is suggesting that you keep the references in the same document, but in a file included with \include. Then you can use \includeonly to produce separate PDFs, one without references and one that is only references. – TH. Apr 17 '11 at 21:03
  • @Elmer: Er, appendices, not references. Not sure what I was thinking. – TH. Apr 18 '11 at 09:45

1 Answers1

10

Here is an example with the refstyle and xr packages (you need some work to get the TOC right). Create your main file, say Main.tex

\documentclass{report}
\usepackage[nokeyprefix]{refstyle}
\usepackage{varioref}
\usepackage{xr-hyper}
\usepackage{hyperref}
    \externaldocument[A-]{App-A}
    \externaldocument[B-]{App-B}
\begin{document}
\chapter{First}
\begin{equation}
  E = m c^2
  \label{eq:Einst}
\end{equation}
In \eqref[s]{eq:Einst} and \eqref*[xr=A-, vref]{eq:e} ...
\end{document}

Then create the Appendix, say App-A.tex

\documentclass{report}
\usepackage[nokeyprefix]{refstyle}
\usepackage{varioref}
\usepackage{xr-hyper}
\usepackage{hyperref}
  \externaldocument[Main-]{Main}

\begin{document}
\appendix
\setcounter{chapter}{0}
\setcounter{page}{50}
\chapter{First}
\begin{equation}
  \mathrm{e}^{i\pi}-1 = 0
  \label{eq:e}
\end{equation}
In \eqref[s,xr=Main-,vref]{eq:Einst} and \eqref*{eq:e} ...
\end{document}

Compile both then the hyperlinks will be active and you can jump between the pdf files

Danie Els
  • 19,694