使用 python 解析乳胶辅助文件中的引用
parse references in latex auxiliary file with python
如果编译包含标签的 Latex 文件,辅助文件将包含与每个标签关联的字符串。
例如,来自以下乳胶源
\documentclass{article}
\begin{document}
\begin{equation}
e^{i\pi} = - 1
\label{myequation}
\end{equation}
\end{document}
编译后生成一个.aux
文件,包含:
\relax
\newlabel{myequation}{{1}{1}}
\gdef \@abspage@last{1}
从该文件中可以看出,myequation
引用的方程具有标签“1”。
我正在寻找 python class 来解析 .aux
文件并生成对应 label_name->string.
的字典
是否有 python 模块或解析器可以做到这一点?
附加信息
我需要这个的原因如下。我有 2 个乳胶源文件,比方说 file1.tex 和 file2.tex。 file2.tex 包含仅在 file1.tex 中出现的对 equations/tables/etc 的引用。
由于与 file1.tex 中每个标签关联的实际字符串是在编译时动态生成的,我的想法是
编译file1.tex
提取对应标签->string
用解析器
用file2.tex中的实际字符串替换\ref{somelabel}
编译file2.tex
第 3 步很容易完成,例如,使用 sed
。第 2 步可能更麻烦。
您可以使用 xr
包(或者 xr-hyper
如果您使用的是 hyperref)简单地从其他文档访问标签:
\documentclass{article}
\usepackage{xr}
\externaldocument{file1}
\begin{document}
test \ref{myequation}
\end{document}
如果编译包含标签的 Latex 文件,辅助文件将包含与每个标签关联的字符串。
例如,来自以下乳胶源
\documentclass{article}
\begin{document}
\begin{equation}
e^{i\pi} = - 1
\label{myequation}
\end{equation}
\end{document}
编译后生成一个.aux
文件,包含:
\relax
\newlabel{myequation}{{1}{1}}
\gdef \@abspage@last{1}
从该文件中可以看出,myequation
引用的方程具有标签“1”。
我正在寻找 python class 来解析 .aux
文件并生成对应 label_name->string.
是否有 python 模块或解析器可以做到这一点?
附加信息
我需要这个的原因如下。我有 2 个乳胶源文件,比方说 file1.tex 和 file2.tex。 file2.tex 包含仅在 file1.tex 中出现的对 equations/tables/etc 的引用。 由于与 file1.tex 中每个标签关联的实际字符串是在编译时动态生成的,我的想法是
编译file1.tex
提取对应标签->string
用解析器
用file2.tex中的实际字符串替换\ref{somelabel}
编译file2.tex
第 3 步很容易完成,例如,使用 sed
。第 2 步可能更麻烦。
您可以使用 xr
包(或者 xr-hyper
如果您使用的是 hyperref)简单地从其他文档访问标签:
\documentclass{article}
\usepackage{xr}
\externaldocument{file1}
\begin{document}
test \ref{myequation}
\end{document}