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}
\leton latex commands is not guaranteeed to work, betetr to use\NewCommandCopyalso using\labelafter the toc can reference the wrong page – David Carlisle Nov 07 '23 at 17:03\NewCommandCopybut I get the same error. In my tests\labelworks for my purpose. – Gabriele Nov 07 '23 at 17:09\label, on longer documents if there is a page break in the table of contents you normally want to reference the first page not the last – David Carlisle Nov 07 '23 at 17:11\maketitleon line 176 – David Carlisle Nov 07 '23 at 17:23labe, I want refer to the last page. – Gabriele Nov 07 '23 at 17:31