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.

Fails
\documentclass{article}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{\R}}
\begin{document}
Let $x \in \R$.
\end{document}
Fixed
\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.

Fails
\documentclass{article}
\renewcommand{\emph}[1]{\textbf{\emph{#1}}}
\begin{document}
This is \emph{important}.
\end{document}
Fixed
\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.

Fails
\documentclass{article}
\def\a{\a x}
\begin{document}
\a
\end{document}
Fixed
\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

Every example on this page was compiled with pdfLaTeX to check that it fails and is fixed as described. All LaTeX errors