LaTeX Error: TeX capacity exceeded, sorry
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.
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.
Try the fix in LetX
Open the editor, paste your code, and compile in 1 second to see the error clear — free, in your browser.
Open LetX Free