# Is it possible to refer some equations or theorems between several working drafts with right numbers automatically?

I am writing several independent drafts. Each of them may turn in a separate paper. I need to cite some results from one draft to the other one. Since non of them is finished, the numbers may change. Are there a way that the numbering systems in all my drafts will update automatically when I make changes in some drafts.

An example: Suppose in the first draft, there are a lemma -- Lemma 3.1 and an equation (3.2.4). These numbers may change since I am still working on this draft.

On the same time, I am writing a second paper. I would like to refer the above mentioned two results: Lemma 3.1 of [1] and (3.2.4) of [1]. Is it possible to let the system update the numbers automatically?

-
A cheap way that I use is \input{<filename>.aux}. –  Hendrik Vogt Feb 11 at 9:15
Thanks Hendrik Volgt, where shall I put this command? –  Anand Feb 11 at 9:20

After edit:

\documentclass{report}
%%%put this in a "real" file
%%% run latex on 'superfilex.tex'
\usepackage{filecontents}
\begin{filecontents}{superfilex.tex}
\documentclass{report}

\begin{document}
\section{other}
\setcounter{equation}{14}% showcase only
$$x=a \label{otherdoc:x}$$
\end{document}
\end{filecontents}
{
\makeatletter
\def\@writefile#1#2{}% does nothing and eats all arguments.
\input{superfilex.aux}
\makeatother
}
\begin{document}

\tableofcontents
\section{this}
$$x=b \label{thisdoc:x}$$
\ref{thisdoc:x} and \ref{otherdoc:x}

\end{document}


Run latex on both files.

The following problems might occur:

• everything which is written to the .aux, besides section and equation labels may raise errors
• unexpected errors may occur
• any change may raise errors

Since you are hiding your actual documents this may not work with your documents. In that case i can be considered as a proof of principle.

A safer approach would be @DavidCarlisle's xr package:

\documentclass{report}
%%%put this in a "real" file
%%% run latex on 'superfilex.tex'
\usepackage{filecontents}
\begin{filecontents}{superfilex.tex}
\documentclass{report}
\begin{document}
\section{other}
\setcounter{equation}{14}% showcase only
$$x=a \label{otherdoc:x}$$
\end{document}
\end{filecontents}
\usepackage{xr}
\externaldocument{superfilex}
\begin{document}

\tableofcontents
\section{this}
$$x=b \label{thisdoc:x}$$
\ref{thisdoc:x} and \ref{otherdoc:x}

\end{document}


Which should works with most common packages/classes including hyperref. Again make sure, that you are pointing to the right path of the external document.

-
Dear bloodworks, thanks a lot. I am still not clear how to set up a file by hand. What is hte suprfile? I will check the package filecontents. Thank you very much! –  Anand Feb 11 at 9:41
Dear bloodworks, I need to refer the right numbers instead of the whole equations. For example, I would like to refer Lemma 3.1 of [2]. I would like to retrieve the right numbers (3.1 for example here). –  Anand Feb 12 at 9:09
Dear bloodworks, thank you very much! Your first approach works well in my case. A minor problem is that the numbers from the other draft keep hyper-links that refer equations with the same numbers in the current document. It would be perfect if one can remove the hyperlinks from these numbers. But this is not a big issue. Thanks a lot! :) –  Anand Feb 12 at 10:11
You should make a MWE on that if it's important. Otherwise try loading hyperref in both documents or not at all. –  bloodworks Feb 12 at 10:12
The second solution also works well! Thanks a lot. –  Anand Feb 12 at 10:15