TeX capacity exceeded, sorry [<what>].
TeX ran out of one of its fixed memory areas. Almost always a command that calls itself forever; rarely a document that is genuinely too big.
Help centre › LaTeX errors › Commands and packages · Error: the build stops or the output is wrong
What the log says
! TeX capacity exceeded, sorry [input stack size=10000].
\R ->\mathbb {\R }
l.4 Let $x \in \R
$.
! ==> Fatal error occurred, no output PDF file produced!What it means
TeX has fixed-size areas for macros being expanded (input stack), nested groups (grouping levels), stored text (main memory) and others; the name in brackets says which ran out. The run stops at once and no PDF is produced. In nearly every case the cause is a definition that expands into itself, so no amount of memory would be enough.
Causes and fixes
Most common first. Each example is a complete document; the first fails with this message, the second is the same document fixed.
1. A command defined in terms of itself
\newcommand{\R}{\mathbb{\R}} expands \R into \R forever; it was meant to be \mathbb{R}. The log shows the looping definition just after the error. Check the definition of the command named there.
\documentclass{article}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{\R}}
\begin{document}
Let $x \in \R$.
\end{document}\documentclass{article}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{R}}
\begin{document}
Let $x \in \R$.
\end{document}2. A command redefined to call its own old meaning
\renewcommand{\emph}[1]{\textbf{\emph{#1}}} calls the new \emph inside itself. Copy the original first, \NewCommandCopy{\oldemph}{\emph}, and call the copy.
\documentclass{article}
\renewcommand{\emph}[1]{\textbf{\emph{#1}}}
\begin{document}
This is \emph{important}.
\end{document}\documentclass{article}
\NewCommandCopy{\oldemph}{\emph}
\renewcommand{\emph}[1]{\textbf{\oldemph{#1}}}
\begin{document}
This is \emph{important}.
\end{document}3. A macro that expands to itself plus more
\def\a{\a x} makes each expansion of \a start another one, until the input stack is full. Every recursive definition needs a case that stops it.
\documentclass{article}
\def\a{\a x}
\begin{document}
\a
\end{document}\documentclass{article}
\def\a{x}
\begin{document}
\a
\end{document}4. A genuinely large job: a huge TikZ or pgfplots figure, or a very long table
When the bracket says main memory size and the source has no loop, the job is just big. Plot fewer samples, externalize the figure as a PDF and include it with \includegraphics, or compile with LuaLaTeX, whose memory grows as needed.
In Manulyx
The editor shows the error with the line where TeX stopped, and the explanation points at the definition that loops.
Write in Manulyx for free · Journal templates
More in commands and packages
- Undefined control sequence.LaTeX met a command it does not know: usually a typo, or a command whose package is not loaded. The log's l. line ends with the culprit.
- Missing number, treated as zero.A command that needs a number or length (\vspace, \setcounter, a width) got a word or nothing. Give it a value such as 1em or 3.
- LaTeX Error: Command \<name> already defined.\newcommand or a package tried to define a name that already exists. Pick another name, use \renewcommand, or drop the clashing package.
- Illegal parameter number in definition of \<name>.A # in a definition does not refer to a declared argument: #1 without [1], #1 in an environment's end code, or a # in a URL. Fix the count or escape it.
- Use of \<name> doesn't match its definition.A command with a special argument syntax, such as \put(x,y) or a \def with delimiters, was called without that syntax. Follow its exact form.
- LaTeX Error: Environment <name> undefined\begin{…} names an environment no loaded package defines: load the package (amsmath for align), fix the spelling, or define it with \newtheorem.
Every example on this page was compiled with pdfLaTeX to check that it fails and is fixed as described. All LaTeX errors