LaTeX error "TeX capacity exceeded, sorry [input stack size=10000]": cause and fix
TeX ran out of one of its internal memory areas and stopped; no PDF is written. The square brackets name the area. The usual reason is not a large document but a command that calls itself without end.
Why it happens
- A command is redefined in terms of itself:
\renewcommand{\thesection}{\thesection.}. The\thesectioninside is the new one, not the old one. The log then namesinput stack size. - A command calls itself inside braces, as in
\newcommand{\nest}{{\nest}}. The log then namesgrouping levels. - A command prints something and then calls itself, as in
\newcommand{\more}{x\more}. The text grows untilmain memory sizeis used up.
How to fix it
- Read the lines below the error in the log. They show the command that repeats, here
\thesection. - Build the format of a counter from the counter, not from the old format:
\renewcommand{\thesection}{\arabic{section}.}. - To extend an existing command, copy it first and call the copy:
\NewCommandCopy{\oldemph}{\emph}, then\renewcommand{\emph}[1]{\oldemph{\textbf{#1}}}.
A document that produces the message
\documentclass{article}
\renewcommand{\thesection}{\thesection.}
\begin{document}
\section{Introduction}
Text.
\end{document}The corrected document
\documentclass{article}
\renewcommand{\thesection}{\arabic{section}.}
\begin{document}
\section{Introduction}
Text.
\end{document}Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.
Finding the line in the editor
The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.
Related pages
- Error Emergency stop
- Error Dimension too large
- How-to Define your own commands in LaTeX
- How-to Counters in LaTeX