0

If I use:

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

in the LaTeX document (.tex file) it works.

But if it try to pass this string by pdlatex engine (I actually don't want to modify my document) in this way:

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

it doesn't work. I get:

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

What's wrong in the pdflatex command?

Note I need to add the labels to make some test on page numbering using \pageref and the .aux file.

This is a 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}

Gabriele
  • 1,815

1 Answers1

1

If I consider the following test file

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

\author{?}\title{??}

\maketitle \tableofcontents

\section{something}

abc \end{document}

and call pdflatex like

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

the produced .aux file is

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

and no error is raised. I used single quotes rather than double quotes, but the result is the same.

Adding \nonstopmode doesn't change the business (I'd prefer to pass -interaction=nonstopmode, though).

egreg
  • 1,121,712