Error

LaTeX Error: TeX capacity exceeded, sorry

The fix

Despite the wording, "TeX capacity exceeded" is usually not about memory. It is a runaway loop: an unclosed brace, a macro that calls itself, or a bad \def. Fix it by checking the command named in the error and your most recent edit. Only genuinely huge documents (massive TikZ or pgfplots) need more memory. There, compile with LuaLaTeX.

Not sure it worked on your document? Paste it into LetX and compile it, free and in the browser.

Why it happens

A missing } or a recursive definition makes TeX expand forever until a buffer fills. The bracketed part of the message, for example [input stack size=5000], names the limit that blew, which hints at the cause: input stack usually means recursion or unbalanced braces, main memory means genuinely too much content.

Example

% Common trigger, a self-referential definition:
\renewcommand{\x}{\x y}   % expands forever

% Or an unclosed brace far above the reported line.

% Genuinely large data plot? Use LuaLaTeX (no fixed cap):
%   latexmk -lualatex main.tex
% or thin the data with \pgfplotsset{compat} + fewer points.

Frequently asked questions

It says [main memory size=...]. Is my document too big?

Sometimes. Very large TikZ/pgfplots figures or huge tables can exhaust classic TeX. Switch to LuaLaTeX, which has no fixed memory ceiling, or reduce the number of plotted data points.

It says [input stack size=5000].

That is recursion or unbalanced braces, not size. Look for a macro that calls itself, or a missing } near your last edit, a small typo, not a big file.

Related LaTeX fixes

Browse all LaTeX problems & fixes, or start with the LaTeX guide.

Learn the topic properly

Try the fix in LetX

Open the editor, paste your code, and compile in seconds to see the error clear. Free, in your browser.

Open LetX Free