Skip to content

Instantly share code, notes, and snippets.

@mblondel
Created May 10, 2013 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mblondel/5553469 to your computer and use it in GitHub Desktop.
Save mblondel/5553469 to your computer and use it in GitHub Desktop.
Cross-referencing in LaTeX.
paper.tex: main manuscript
supp.tex: supplementary material
Cross-referencing
-----------------
We want to cross-reference equations in paper.tex from supp.tex.
Add the following to supp.tex:
\usepackage{xr}
\externaldocument{paper}
Then use \ref, \eqref, \section etc normally.
Equation numbering
------------------
In order for the equation numbering in supp.tex to start from the last equation
in paper.tex, add the following to paper.tex:
\usepackage{newfile}
[...]
\newoutputstream{stream}
\openoutputfile{counters}{stream}
\addtostream{stream}{
\protect\setcounter{equation}{\arabic{equation}}%
}
\closeoutputstream{stream}
\end{document}
This will save the equation counter to a file named "counters".
Other counters include: part, chapter, section, subsection, subsubsection,
paragraph, subparagraph, page, equation, figure, table, footnote, mpfootnote
Then include the "counters" file in supp.tex:
\input{counters}
\addtocounter{equation}{1}
To get the references correctly, each file must be compiled with pdflatex two
(or three) times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment