aux 文件基本上由在文档开头读取和扩展的 tex 命令组成。命令
\AtBeginDocument{\makeatletter\input{test2.aux}\makeatother}
至少在命令方面,效果几乎相同\newlabel
。另一方面,命令效果不太好。也许这与命令是实际写入目录的命令\@writefile{toc}
有关。\@starttoc{toc}
无论如何,我试图合并目录,而实际上每次都重复整个文档。以下内容用于创建test2.aux
:
\documentclass{book}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\setcounter{part}{1}
\setcounter{page}{11}% this you will have to do manually
\part{Volume 2}
\chapter{v2 first}\label{test}
\chapter{v2 second}
\end{document}
读的是
\documentclass{book}
\AtBeginDocument{\makeatletter\input{test2.aux}\makeatother}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{Volume 1}
\chapter{v1 first}\pageref{test}%\newlabel{test} from test2.aux
\chapter{v1 second}
\end{document}
注意\pageref{test}
,有效。
答案1
我会使用在文档末尾\input
直接写入文件的语句。关键不是使用,而是只使用。.aux
\immediate\write
\write
\makeatletter
\AtEndDocument{%
\write\@auxout{%
\string\input{test2.aux}
% Other \string\input{test3.aux} etc. here
}%
}
\makeatother
会写\input{test2.aux}
在文档末尾,而不是中间某处。其他要包含的文件可以用\string\input{test3.aux}
etc添加。
为了更好地检查,\InputIfFileExists{}{}{}
应该使用,但为了简单起见,我现在省略了此功能。
\documentclass{book}
\makeatletter
\AtEndDocument{%
\write\@auxout{%
\string\input{test2.aux}
% Other \string\input{test3.aux} etc. here
}%
}
\makeatother
%\AtBeginDocument{\makeatletter\input{test2.aux}\makeatother}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{Volume 1}
\chapter{v1 first}\pageref{test}%\newlabel{test} from test2.aux
\chapter{v1 second}
\end{document}
foo.aux
这是(合并文档)的内容:
\relax
\@writefile{toc}{\contentsline {part}{I\hspace {1em}Volume 1}{1}}
\@writefile{toc}{\contentsline {chapter}{\numberline {1}v1 first}{3}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\@writefile{toc}{\contentsline {chapter}{\numberline {2}v1 second}{5}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\input{test2.aux}
答案2
Hupfer 解决方案的一个细微变化,允许所有项目共享辅助文件。项目test
:
\documentclass{book}
\newif\iffirstaux
\firstauxtrue
\makeatletter
\AtEndDocument{%
\write\@auxout{\string\iffirstaux
\string\firstauxfalse
\string\InputIfFileExists{test2.aux}{}{}%
\string\firstauxtrue
\string\fi}%
}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{Volume 1}
\chapter{v1 first}\pageref{test}%\newlabel{test} from test2.aux
\chapter{v1 second}
\end{document}
项目test2
:
\documentclass{book}
\newif\iffirstaux
\firstauxtrue
\makeatletter
\AtBeginDocument{%
\write\@auxout{\string\iffirstaux
\string\firstauxfalse
\string\InputIfFileExists{test.aux}{}{}%
\string\firstauxtrue
\string\fi}%
}
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\setcounter{part}{1}
\setcounter{page}{11}% this you will have to do manually
\part{Volume 2}
\chapter{v2 first}\label{test}
\chapter{v2 second}
\end{document}
请注意,辅助文件必须\input
按顺序排列,一些在开头,一些在结尾。