Fix the TeX capacity exceeded error in LaTeX.
The TeX capacity exceeded error is almost never a shortage of memory. It means your document has trapped the compiler in an infinite loop, an unclosed brace, a macro that calls itself or a conflicting package option.
The short answer: check the bracketed message in the error. If it names the input stack size, look for a runaway macro, an unclosed brace or a package conflict near your last edit. If it names main memory, your document or figure plots are too large and need LuaLaTeX.
Read the bracketed limit
When TeX gives up, it prints a message naming the exact buffer that filled. The bracketed part tells you what went wrong before the compiler stopped.
An input stack size error means TeX is trapped in recursion. A macro is expanding endlessly, a command is calling itself without an exit condition, or an unclosed brace has thrown off the parser. The line number in the log points to where TeX finally broke, but the real bug is often dozens or hundreds of lines earlier.
A main memory size error means your document genuinely exhausted classic TeX's static arrays. This happens with huge datasets, complex TikZ figures, or massive tables loaded all at once.
Four common triggers and how to fix them
Package conflicts and obsolete macros
Certain packages redefine standard commands or hook into character codes in ways that create infinite loops. The hanging package often conflicts with prime symbols on math variables, and deprecated packages like ngerman can trigger stack overflows on modern TeX distributions.
% Fix: remove the conflicting package or pass the safe option \usepackage[notquote]{hanging}Unclosed environments or missing braces
A missing closing brace or an unclosed block environment inside a Beamer frame or a custom macro forces TeX to consume stack frames until the limit blows. Check your most recent edits for stray brackets.
% Fix: ensure every block has a title argument or empty brackets \begin{block}{} \begin{itemize} \item foo \end{itemize} \end{block}Missing \end{document} at file end
If your source file ends without an \end{document} command, pdfLaTeX drops into an interactive terminal prompt looking for input. Typing commands there or letting it run off the end triggers a stack overflow on \end definitions.
% Fix: always make sure the file closes cleanly \end{document}Massive data sets in TikZ or PGFPlots
Plotting tens of thousands of data points directly in classic TeX consumes all available memory words. Switch your engine from pdfLaTeX to LuaLaTeX in your project settings, as LuaLaTeX allocates memory dynamically and has no fixed ceiling.
How to isolate the bug
If the log file points to a line that looks completely normal, do not trust the line number. Comment out your last added chapter, table or package import and recompile. If the error disappears, uncomment halves of the removed text until you find the exact offending line.
Texeno captures compiler output and highlights the problem area so you can jump straight to the source without scrolling through thousands of lines of terminal logs.
Questions
What does TeX capacity exceeded, sorry [input stack size=5000] mean?
It means TeX's internal recursion stack is full. It is almost always caused by an infinite macro loop, an unclosed brace, or a package conflict rather than a large document.
Does this error mean my document is too long?
No. Page count rarely causes stack size errors. A 300-page novel with simple text compiles fine, while a single page with a recursive macro will crash immediately.
How do I fix main memory exhaustion in TeX?
Switch your project compiler from pdfLaTeX to LuaLaTeX. LuaLaTeX allocates memory dynamically at runtime, removing the fixed array limits built into older TeX engines.
Try your own paper in Texeno.
Start free, upload a project as a .zip and press Recompile. Upgrade when you need longer compiles.
Start writing