If you compile a latex file containing labels, the auxiliary file will contain the string associated with every labels.
For example, from the following latex source
\documentclass{article}
\begin{document}
\begin{equation}
e^{i\pi} = - 1
\label{myequation}
\end{equation}
\end{document}
after compiling a .aux
file is generated, containing:
\relax
\newlabel{myequation}{{1}{1}}
\gdef \@abspage@last{1}
From this file one can see that the equation referenced with myequation
has label "1".
I am looking for a python class that parses the .aux
files and generates a dictionary with the correspondence label_name->string.
Is there a python module or parser that does that?
Additional information
The reason why I need this is the following. I have 2 latex source files, let's say file1.tex and file2.tex. file2.tex contains references to equations/tables/etc which are present only in file1.tex. Since the actual string associated to every label in file1.tex is dynamically generated at compile time, my idea would be to
compile file1.tex
extract the correspondence label->string
substitute
\ref{somelabel}
with the actual string in file2.tex with a parsercompile file2.tex
Step 3 is easily done, for example, using sed
. Step 2 is perhaps more cumbersome.
CodePudding user response:
You can simply access the labels from the other document with the xr
package (or xr-hyper
if you're using hyperref):
\documentclass{article}
\usepackage{xr}
\externaldocument{file1}
\begin{document}
test \ref{myequation}
\end{document}