TeX capacity exceeded error

I am definitely dumb. Well, LaTeX has its part in it, too.

It turns out that all of a sudden, I started having this error when compiling a .tex file:

! TeX capacity exceeded, sorry [input stack size=1500].

After googling for an answer, I found out that the “stack size” limit is defined in the following file:

/usr/share/texmf/web2c/texmf.cnf

However, changing the value made no good: any limit, no matter how large, would be “exceeded”. The reason (after a little more hitting my head against the wall) is that there was an infinite loop in the input .tex (maybe \input{file.tex} inside file.tex, or somesuch). 10 hours (well, 5 minutes, actually) of head-banging later, when I was pretty sure no freaking infinite loop was there, I found the answer:

I had deleted the \end{document} tag!!

Now, yes, how stupid am I? And… how stupid is LaTeX to give that silly error, instead of:

TeX warning: You are too dumb, and forgot an \end{document}

43 Comments »

  1. Krisztián said,

    July 10, 2007 @ 0:53 am

    For me “\usepackage{graphicx}” was the bad guy.

  2. krisztián said,

    July 10, 2007 @ 0:56 am

    Oh, forgot to mention it was pdflatex.

  3. Tazabi said,

    October 1, 2007 @ 22:06 pm

    I just had a 2hr hunt for a solution for such a problem and the problem was that I had a \verb in a caption.

  4. Engineer said,

    November 21, 2007 @ 18:04 pm

    OMG I have jsut spent far too long trying to resolve this.

    My problem was because of an errant entry in my bibtex file, diss.bib I mistakenly had a url{} element, which apparently shouldn’t be there!

    Posting this here to help other googlers!

    Original error:
    ———————————
    ! TeX capacity exceeded, sorry [input stack size=5000].
    \hmode@bgroup ->\leavevmode
    \bgroup
    l.7

    If you really absolutely need more capacity,
    you can ask a wizard to enlarge me.

  5. isilanes said,

    March 5, 2008 @ 21:15 pm

    Taken from my former blog URL at: http://handyfloss.wordpress.com/2006/11/30/tex-capacity-exceeded-error/

    Mikaël said:

    I had the same error:
    ! TeX capacity exceeded, sorry [input stack size=5000].
    \hmode@bgroup ->\leavevmode
    \bgroup
    l.7

    Apparently it has indeed something to do with the url{} tag in my .bib file. However, I need this entry because I need to be able to reference to certain websites. (bibliography rules at my university require that i refer to the exact urls.)

    Any suggestions?

    Then, self-answered with:

    LOL found it. It’s as easy as opening your .bib file in your favorite text/tex-editor, and adding \usepackage{url} at the beginning of the file. Apparently then latex also knows how to read a url as a url within the .bib file.

    My answer:

    Thanks for your input, Mikaël. The best part of a blog is learning from comments to one’s posts! :^)

  6. Johann said,

    July 3, 2008 @ 16:03 pm

    The way I got this error was that I forgot the {} for the title of a block environment (using beamer):

    %%% error: %%%
    \begin{block}

    \end{block}

    %%% no error: %%%
    \begin{block}{}

    \end{block}

  7. N said,

    August 20, 2008 @ 1:04 am

    I have a paper that is overdue for a conference and I just got this error. The annoying thing is that I made no more than a minor change to my original tex file and my .bib file and all of a sudden bibtex stopped working with precisely that error. More annoying, I’ve undone those changes and the error persists. It’s enough to push me off of LaTeX, since one of the major reasons why I use it is the ease of bibtex.

    Smacking head against table.

    Any ideas?

  8. N said,

    August 20, 2008 @ 1:26 am

    OK, for me it also seems to be a URL problem. Unfortunately, I already have \usepackage{url} in the document and in the bibtex file. Any other ideas on how to fix it?

  9. isilanes said,

    August 21, 2008 @ 13:47 pm

    Sorry, N, nothing from the top of my head. If you could post the .tex file I could try to debug it, but I will not be much online, since I’m on vacations until September.

  10. John said,

    August 28, 2008 @ 14:00 pm

    Thanks Johann for your post (beamer and block). Your comment saved my a couple of hours and LOTS of frustration.

  11. N said,

    September 2, 2008 @ 21:19 pm

    Thanks. I ended up stripping all the URL information, and then it worked.

  12. TeX capacity exceeded error « handyfloss said,

    September 17, 2008 @ 10:43 am

    […] Entry available at: http://handyfloss.net/2006.11/tex-capacity-exceeded-error/ […]

  13. Fernando Rozenblit said,

    November 3, 2008 @ 19:50 pm

    For me it was a “\begin{block}” that should be “\begin{block}{}”, using beamer.

  14. isilanes said,

    November 4, 2008 @ 16:34 pm

    Thank you all for your comments. Apparently this error can be triggered in many ways. But the bottom line in most/all cases is that it is a stupid error from the user side, yet a simple (syntax) test that the LaTeX compiler doesn’t run. It would be great to have a “pre-processor” that read the .tex file looking for obvious errors such as the above, then warn about them, instead of trying to compile and fail.

  15. kok said,

    March 26, 2009 @ 12:23 pm

    To add to the list:

    I got this error because I changed the spacing between items

    \let\origitemize\itemize
    \def\itemize{\origitemize\itemsep-0.5\baselineskip}

    As this is a common tip to change the line space within an item environment, others might encounter the same problem.

  16. isilanes said,

    March 26, 2009 @ 13:06 pm

    Thanks for your input, kok!

  17. Dai said,

    November 15, 2009 @ 18:12 pm

    Thanks to Johan for highlighting what, for me, was the problem: always put a pair of curly braces when starting each block, i.e.

    \begin{block}{}

  18. Dai said,

    November 15, 2009 @ 18:13 pm

    Should have mentioned that my problems were also encountered with Beamer

  19. Luca said,

    May 7, 2010 @ 16:23 pm

    Thank you so much Johann, it was the same for me. The problem was a \begin{block} without the required title in Beamer.

  20. didietok said,

    May 19, 2010 @ 3:20 am

    OMG, how stupid am I? i forgot to write {} after \begin{block}

  21. bill said,

    September 3, 2010 @ 21:51 pm

    I also encountered this error with MiKTeX and TeXnicCenter on Windows 7.
    What did the trick for me was to delete the temporary junk files (i.e. all except the .tex and .bib).
    Maybe I should also mention, that they were left overs from working on some linux machine…

  22. helen said,

    October 11, 2010 @ 17:56 pm

    I got this error, found this page and spotted I had URLs in my bibtex file, so I deleted them because they weren’t actually necessary for me.

    Error didn’t go away. Frustration.

    Eventually realised that the .bbl file (that is created when you bibtex something) is not fixed unless you delete it and re-bibtex, as it were.

    Deleted it, re-ran bibtex, it worked. Hooray!

  23. Michael said,

    October 20, 2010 @ 12:25 pm

    Don’t know whether anyone has reported this one yet… Using a double-backslash inside a figure caption, instead
    of the backslash-newline command, caused the stupid error in my case. As soon as I read the posts in this blog
    and knew how to go about finding the culprit, I could identify the erroneous text and then find what was wrong with
    it. Needless to say: double-backslash in normal text, outside figure captions, is no problem. Thanks to all who have
    posted messages regarding this, because that way the time I wasted looking elsewhere was minimised.

  24. cynthia said,

    November 6, 2010 @ 2:25 am

    My ‘capacity exceeded’ error was courtesy of an extra ‘\end{itemize}’ line

  25. Dilip said,

    February 22, 2011 @ 14:53 pm

    In my case it was an extra \begin{itemize} and \end{itemize}.

  26. Andy said,

    March 23, 2011 @ 10:26 am

    I ran into this problem when I changed the language setting on my thesis to English (Canadian) instead of just English. Luckily I had a backup that I diff’ed to figure it out!

  27. First Time Beamer said,

    May 19, 2011 @ 14:37 pm

    Worked the same way for me, thanks!

    #

    Johann on 03 Jul 2008 at 16:03 pm #

    The way I got this error was that I forgot the {} for the title of a block environment (using beamer):

    %%% error: %%%
    \begin{block}
    …
    \end{block}

    %%% no error: %%%
    \begin{block}{}
    …
    \end{block}

  28. kimsan said,

    May 24, 2011 @ 16:26 pm

    I got these error when i added some options to a \begin{axis} like:

    \begin{axis}[
    legend style={fill=white}
    minor tick num=3
    ]

    and forgot to separate them by comma “,” like:

    \begin{axis}[
    legend style={fill=white}, % <—- a comma!!!
    minor tick num=3
    ]

    Hope this helps someone.

  29. Andre said,

    May 26, 2011 @ 12:31 pm

    I had the same error,

    ———————————
    ! TeX capacity exceeded, sorry [input stack size=5000].
    \hmode@bgroup ->\leavevmode
    \bgroup

    And I tryed to use the \usepackage{url} on my .bib and doesn’t worked, the only thing it was getting off all the url’s of my bib file…

    Well, any other suggestion is welcomed!
    Thanks for the answers guys!

  30. Andre said,

    May 26, 2011 @ 12:49 pm

    ok, I found other solution…
    My mendeley and JabRef was made my bib file for me, then the url on .bib file was like:

    url = {wwwwwwwww}

    Then after read some posts here I noticed that the way of the url was created by this softwares was wrong, then I changed by this: (removing the = )

    url{wwwwwwww}

    and also using the package \usepackage{url} worked!!!

    Thanks a lot guys!

  31. Vik said,

    October 24, 2011 @ 18:42 pm

    Hi guys!

    I had the same error,

    ———————————
    ! TeX capacity exceeded, sorry [input stack size=5000].

    And in my case it was the one first mentioned by Johann (to add at least an empty title to the block):

    \begin{block}{}
    …
    \end{block}

    Thank you very much! I saved a lot of time and nerves on this!!!:-)

  32. stefan said,

    February 1, 2012 @ 9:16 am

    mine was due to the \url tag in my bib file.. i used the wikipedia bib generator to generate a nice formatted bib tag.. but apparently latex threw up because of it.

  33. mario said,

    February 1, 2012 @ 22:23 pm

    MY ERROR WAS IN SOME WAY DIFFERENT FROM THE PREVIOUS

    TeX capacity exceeded, sorry [input stack size=1500].\select@language {italian}

    SOMEONE HAS IDEAS WHAT TO DO ?

  34. rob said,

    February 15, 2012 @ 16:25 pm

    I had the same error using lyx 2.0. The error occurred after I added the enumitem module to an existing beamer file that already had enumerations in it. Probably a conflict between enumerations.

  35. Arjan said,

    July 19, 2012 @ 18:24 pm

    One more way to get this error is using gb4e (for numbered examples and glosses) and bibtex. Using only gb4e gave me no errors, but after adding \cite references it broke. Adding “\noautomath” right after “\usepackage{gb4e}” fixed this (see gb4e manual).

  36. ellia said,

    October 3, 2012 @ 13:14 pm

    Thank you so much for this post!
    Even though my problem was not mentioned in the previous comments, they let me now that the reason can be any random syntax error.

    In my case, there is a line in my paper: “…with “+” and “-” polarities”,
    typed into TeX as: “…with “+” and “-” polarities”, which produced an error.
    However, after typing it in as “…with “+” and “\text{–}” polarities” everything works fine.

    The simple “-” version worked fine before, and I’m a beginner TeX user, so I don’t know what might be the case here, but anyway – it works now. I thought I’d share yet another possible error trigger for other googlers to check for.

  37. Michael said,

    November 25, 2012 @ 0:32 am

    deleting all url’s, deleting all non-essential files, emptying the recycle bin, and deleting my bibliography after backing it up on my e-mail has solved the problem for me for now.. gotta love computers..

  38. Michael said,

    November 25, 2012 @ 0:34 am

    the backing up bibliography and deleting it was a solution that worked for another innexplicable problem I had.. (changes in the bibliography not being reflected in the document..)

  39. antoine said,

    February 6, 2013 @ 21:32 pm

    quickly, for the record, mine was with lyx and beamer in math mode

    I had to replace the ‘ symbol (prime) in math mode by ^{\prime} and it worked..

  40. D said,

    February 12, 2013 @ 13:21 pm

    One more for the record:

    There is some issue with the harvard bibstyle and latex2html (related to html.sty). Uninstalling latex2html from the system worked for me.

  41. T said,

    June 5, 2013 @ 17:48 pm

    For me it was having an underscore in the images file name e.g.

    ! TeX capacity exceeded, sorry [input stack size=5000].
    \PU-cmd …otect \@typeset@protect \@inmathwarn #1
    \expandafter \ifx \csname …
    l.109 …degraphics[scale=0.85]{img_name.png}

    ! ==> Fatal error occurred, no output PDF file produced!
    Transcript written on main.log.

    Changed to imgName.png and all works fine!

  42. Cheerbucket said,

    November 27, 2014 @ 17:24 pm

    For me it was a problem in the preamble. I included
    \usepackage{apacite}

    but not
    \usepackage{natbib}

    Compiled fine once I included both statements.

  43. smo said,

    May 24, 2015 @ 22:20 pm

    I had an errant “\ref” without the actual referring tag hanging out in my text. Posting this for any googlers.

RSS feed for comments on this post · TrackBack URI

Leave a Comment