通过 pdflatex 引擎传递更新的命令

通过 pdflatex 引擎传递更新的命令

如果我使用:

\AtBeginDocument{\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{\oldtableofcontents\label{TOC}}
\let\oldmaketitle\maketitle
\renewcommand{\maketitle}{\oldmaketitle\label{BODY}}}

LaTeX文档(.tex文件)中它起作用。

但是如果它尝试通过pdlatex引擎传递这个字符串(我实际上不想修改我的文档):

pdflatex "\AtBeginDocument{\let\oldtableofcontents\tableofcontents\renewcommand{\tableofcontents}{\oldtableofcontents\label{TOC}}\let\oldmaketitle\maketitle\renewcommand{\maketitle}{\oldmaketitle\label{BODY}}} \
\nonstopmode \
\input{mydocument.tex}"

它不起作用。我得到:

! TeX capacity exceeded, sorry [input stack size=10000].
\oldmaketitle ->\oldmaketitle 
                              \label {BODY}
l.176 \maketitle
                \flushbottom
!  ==> Fatal error occurred, no output PDF file produced!

命令中有什么错误pdflatex

笔记我需要添加标签来对文件的页码进行一些\pageref测试.aux

这是一个 MWE:

\documentclass{article}
\usepackage{blindtext}

\begin{document}

\author{A. Uthor}

\title{Article's title}

\maketitle
\pagenumbering{roman}
\tableofcontents
\pagenumbering{arabic}

\section{First section}
\blindtext

\subsection{First subsection}
\blindtext
\subsubsection{First subsubsection}
\blindtext
\subsubsection{Second subsubsection}
\blindtext
\subsubsection{Third subsubsection}
\blindtext

\subsection{Second subsection}
\blindtext
\subsubsection{First subsubsection}
\blindtext
\subsubsection{Second subsubsection}
\blindtext
\subsubsection{Third subsubsection}
\blindtext
\subsection{Third subsection}
\blindtext
\subsubsection{First subsubsection}
\blindtext
\subsubsection{Second subsubsection}
\blindtext
\subsubsection{Third subsubsection}
\blindtext

\section{Second section}
\blindtext
\subsection{First subsection}
\blindtext
\subsubsection{First subsubsection}
\blindtext
\subsubsection{Second subsubsection}
\blindtext
\subsubsection{Third subsubsection}
\blindtext
\subsection{Second subsection}
\blindtext
\subsubsection{First subsubsection}
\blindtext
\subsubsection{Second subsubsection}
\blindtext
\subsubsection{Third subsubsection}
\blindtext
\subsection{Third subsection}
\blindtext
\subsubsection{First subsubsection}
\blindtext
\subsubsection{Second subsubsection}
\blindtext
\subsubsection{Third subsubsection}
\blindtext

\section{Third section}
\blindtext
\subsection{First subsection}
\blindtext
\subsubsection{First subsubsection}
\blindtext
\subsubsection{Second subsubsection}
\blindtext
\subsubsection{Third subsubsection}
\blindtext

\end{document}

答案1

如果我考虑以下测试文件

%%% patchgn.tex %%%
\documentclass{article}
\begin{document}

\author{?}\title{??}


\maketitle
\tableofcontents

\section{something}

abc
\end{document}

并调用pdflatex类似

pdflatex '\AtBeginDocument{\NewCommandCopy\oldtableofcontents\tableofcontents\renewcommand{\tableofcontents}{\oldtableofcontents\label{TOC}}\NewCommandCopy\oldmaketitle\maketitle\renewcommand{\maketitle}{\oldmaketitle\label{BODY}}} \input{patchgn}'

生成的.aux文件是

\relax 
\newlabel{BODY}{{}{1}{}{}{}}
\newlabel{TOC}{{}{1}{}{}{}}
\@writefile{toc}{\contentsline {section}{\numberline {1}something}{1}{}\protected@file@percent }
\gdef \@abspage@last{1}

并且没有出现任何错误。我使用了单引号而不是双引号,但结果是一样的。

添加\nonstopmode不会改变业务(-interaction=nonstopmode尽管我更愿意通过)。

相关内容