Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use this piece of code in the preamble, obtained from Environment that counts words inside:

  \marginpar{\arabic{words} words}}

I use this in my main file that includes several chapters. If I include up to the end chapter 4 (33599 words) then the counting environment works fine. If I include the next chapter (~6K words) I get the TeX capacity exceeded error. Having tested and excluded all other options it is definitely down to the assignment environment reaching a buffer(?) limit at some point over 33.599K words. I am not sure how to create a MWE for this particular case without sharing my actual work which for obvious reasons I cannot do.

share|improve this question
This may be just too hard for TeX, I don't know. Is using LuaLaTeX an option? If yes, you might want to look at this: gist.github.com/phi-gamma/2622252 (didn't test, just googled it). –  mbork Feb 23 '13 at 9:45
You can try whether you get the error with lots of automatically generated contents like this 100k long lipsum text. Then you post and example with a text PUT 100k OF TEXT HERE instead of the long text. –  yo' Feb 23 '13 at 10:20
\blindtext also takes an optional repetition argument which could be made large enough to trigger the problem. –  Christian Feb 23 '13 at 10:42
Hi DGarside. A tip: if you copy and paste directly the link of the answer in your question the title will appear. –  Claudio Fiandrino Feb 23 '13 at 11:13
Can you add the complete error text? –  egreg Feb 23 '13 at 11:32

1 Answer 1

up vote 11 down vote accepted

If I run the document below as posted I get a save stack error:

[30] [31] [32] [33] [34] [35] [36] [37]
! TeX capacity exceeded, sorry [save size=50000].

If I uncomment the two lines marked %%%% then it runs to the end

Output written on xew33.pdf (84 pages).

and reports 51720 words

enter image description here



\expandafter\ifx\csname wordcount@xs@searchlist\endcsname\relax
  \marginpar{\arabic{words} words}%
\begingroup\expandafter\def\csname @currenvir\endcsname{assignment}%


\def\a{one two three four five six seven eight nine ten. }
\def\b{red yellow green blue. }
\def\c{apple orange pear banana.}


one one two three

one two three four five six


the document environment in LaTeX plays a similar trick to use the environment syntax but avoid making a group around the whole document.

share|improve this answer
This does calculate for size > 50000 but I do not seem able to have one assignment environment follow on immediately after another. The second environment registers as zero. Would the way around that be to create assignment_main and assignment_bibliography environments? –  DGarside Feb 28 '13 at 17:12
code updated to re-use the existing search structure seems to get the right answer on a couple of smaller lists at the end, see posted image –  David Carlisle Feb 28 '13 at 18:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.