FormaTeX
FatalCommands & Packages

TeX Capacity Exceeded

! TeX capacity exceeded, sorry [main memory size=N].

What this error means

LaTeX ran out of internal memory while processing your document. This can happen with very large documents, deeply nested structures, or infinite loops caused by recursive macro definitions.

Common causes

  • Recursive \newcommand definition that calls itself
  • Extremely large document with many TikZ diagrams or complex tables
  • A package bug causing infinite expansion
  • Too many nested environments or groups

How to fix it

If you have a recursive macro, fix the definition to terminate properly. For large documents, split them using \include{} and compile chapters separately. If caused by a package, try updating it or filing a bug report.

Code examples

Causes the error
\documentclass{article}
\newcommand{\myloop}{\myloop}  % Infinite recursion!
\begin{document}
\myloop
\end{document}
Fixed
\documentclass{article}
% Define commands that terminate
\newcommand{\mytext}{This is finite text.}
\begin{document}
\mytext
\end{document}

Related errors

Test the fix live

Paste your LaTeX into the playground and compile instantly.

One quick thing

We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.

Cookie policy