我正在准备一个由两部分组成的文档(两个单独的 TEX 文件,两个单独的 PDF 文件),其中第二部分是第一部分的延续。因此,定理、引理等的编号是从第一个文档开始的。有人能建议如何从文档 1 中读取最后一个定理编号,向其添加 1,然后从该编号开始对文档 2 中的定理进行编号吗?
MWE(复制):
doc1.tex
\documentclass{article}
\usepackage[english]{babel}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
Let $f$ be a function whose derivative exists in every point, then $f$ is a continuous function.
\end{theorem}
\end{document}
doc2.tex
\documentclass{article}
\usepackage[english]{babel}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
New theorem, with theorem number 2
\end{theorem}
\end{document}
答案1
保存来自 doc1 的值
\documentclass{article}
\usepackage[english]{babel}
\newwrite\zzz
\immediate\openout\zzz=from\jobname.tex
\AtEndDocument{%
\immediate\write\zzz{\string\setcounter{theorem}{\number\value{theorem}}}
\immediate\closeout\zzz
}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
Let $f$ be a function whose derivative exists in every point, then $f$ is a continuous function.
\end{theorem}
\end{document}
并在 doc2 中使用
\documentclass{article}
\usepackage[english]{babel}
\newtheorem{theorem}{Theorem}
\input{fromdoc1}
\begin{document}
\begin{theorem}
New theorem, with theorem number 2
\end{theorem}
\end{document}