My attempt at understanding the wizardry may be somewhat brute force-ish, but it does touch on some of the questions contained in memory usage output. It does not describe how to modify (or increase these quantities).
Much of the discussion below revolves around a modification to the following, basic, "Hello world" minimal example. Let's call it Hello world1. The superscript denotes an initial MWE, with subsequent modifications denoted by an increased superscript:
\documentclass{article}% Hello world 1
\begin{document}
Hello world.
\end{document}
TeX statistics
( ) strings out of ( )
As-is, Hello world1 uses 203 strings out of 493633. Modifying this to Hello world2:
\documentclass{article}% Hello world 2
\begin{document}
Hello world. Hello world.
\end{document}
leaves things unchanged across all statistics. However, defining Hello world as part of a macro (via \def or \newcommand) to Hello world3
\documentclass{article}% Hello world 3
\def\helloworld{Hello world.}% \helloworld -> Hello world.
\begin{document}
\helloworld
\end{document}
causes a unit increase in this part of TeX's memory usage, bumping it up to 204. Macro definition increases string, but usage does not. That is, have (say) 50 \helloworld commands in a document would still only use 204 strings. Strings are also used when reading from a file using \input or \include (Hello world4):
\documentclass{article}% Hello world 4
\begin{document}
\input{helloworld.txt}% Hello world.
\end{document}
\include uses fewer strings, but necessarily requires the file to have a .tex file extension.
( ) string characters out of ( )
Hello world1 has 2308 string characters, and the same goes for Hello world2. However, Hello world3 uses 2318 string characters, stemming from the 10-letter control sequence \helloworld. The that extent, brevity (with clarity) reigns supreme when it comes to defining macros. That is, it's best to avoid Hello world5:
\documentclass{article}% Hello world 5
\def\helloworldmacrothatwillwritehelloworldastheoutput{Hello world.}%
\begin{document}
\helloworldmacrothatwillwritehelloworldastheoutput
\end{document}
( ) words of memory out of ( )
With only Hello world1, already 49245 words of memory were used. This remains unchanged using Hello world2,3. However, if \helloworld is defined to contain a fairly large paragraph (like in the case of the lipsum package), the words are bumped up (by 1000 to 50245 in this case) Hello world6:
\documentclass{article}% Hello world 6
\newcommand\helloworld{%
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
turpis purus, posuere et suscipit eu, dictum ac lacus. In velit
orci, pulvinar nec tristique quis, congue id diam. Sed sit amet
augue tellus, sit amet placerat sapien. Vivamus scelerisque placerat
libero id auctor. Donec laoreet auctor velit, eu cursus nulla
bibendum a. Mauris id tellus vitae felis sodales sagittis. Curabitur
mollis vehicula sagittis. In pharetra elit vel dui mattis dapibus.
Pellentesque commodo magna eu sem faucibus fermentum. Nunc in turpis
arcu, nec venenatis enim. Quisque sed velit id velit ullamcorper
suscipit mattis a ipsum. Etiam viverra eleifend tellus, eget sodales
enim varius at. Proin quis nibh mi. Nullam sed nisl id mauris
aliquam feugiat.}
\begin{document}
\helloworld
\end{document}
In fact, using the code provided by @Yiannis to produce 15283 pages of wholesome goodness uses a only(!) 145453 word of memory - a 189% increase from Hello world6. On my system I was even able to up the 37000 limit to 100000, producing a ~61.5MB, 41305 page document in just over 3 minutes, without any noticeable increase in memory usage. This is undoubtedly due to the line- and paragraph breaking that flush some memory; following @egreg's comment about \par removal, only 900 iterations yields 2746549 words of memory (>90% usage). It is also evident from the compiling output that TeX "takes a deep breath" as it digests the intake, before spewing out the 222 pages of breath-taking beauty. Knuth also mentions this on p 300 in the TeX Book:
If you have specified a gigantic paragraph or a gigantic alignment
that spans more than one page, you should change your approach,
because TeX has to read all the way to the end before it can complete
the line-breaking or the alignment calculations; this consumes huge
amounts of memory space.
( ) multiletter control sequences out of ( )
(La)TeX defines a number of single-letter control sequences by default: \\, \c (for cedilla), \b (for bar), etc. And, since there is a limit to the number of single-letter control sequences that are available, it is more constructive to count multiletter control sequences. This is an obvious count to establish. Hello world1 produces 3587 such control sequences, giving justice to all the behind the scenes prep work (La)TeX does in order get you started. In fact, the 8000 odd lines of latex.ltx is peppered with macro definitions (and \lets). Hello world3, as expected, has 3588 multiletter control sequences.
Further to the above excerpt from the TeX Book, Knuth writes (p 300):
If you have built up an enormous macro library, you should remember that TeX has to remember all of the replacement texts that you define; therefore if memory space is in short supply, you should load only the macros that you need.
This is especially true for rich document classes like beamer and (say) the hyperref package. In fact, this Hello world7 in beamer:
\documentclass{beamer}% Hello world 7
\begin{document}
Hello world.
\end{document}
uses
15105 strings out of 493633;
280253 string characters out of 3146724;
353989 words of memory out of 3000000; and
18064 multiletter control sequences out of 15000+200000.
( ) words of font info for 39 fonts, out of ( )
( ) hyphenation exceptions out of ( )
Hello world1 covers 831 hyphenation exceptions, while Hello world8:
\documentclass{article}% Hello world 8
\begin{document}
\hyphenation{He-ll-o} \hyphenation{w-o-r-ld}
Hello world.
\end{document}
has 833. Understandably, this is language dependent. Also, only global hyphenation/discretionary settings affect hyphenation exceptions, while local/temporary settings (like He\-ll\-o) do not affect it.
( ) stack positions out of ( )
These refer to (from the TeX Book, p 300):
i: input stack size (simultaneous input sources);
n: semantic nest size (unfinished lists being constructed);
p: parameter stack size (macro parameters);
b: buffer size (characters in lines being read from files); and
s: save size (values to restore at group ends)
I did not venture into seeing how these are modified. However, as suggested in the TeX Book (p 300), using the \tracingrestores=1 in your document would produce a tracking report (in your .log file) of how TeX removes saved items from the stack at the end of every group.
PDF statistics
( ) PDF objects out of ( )
A very straight-forward discussion on PDF objects mentions that there are essentially three types:
- Annotations
- Text, and
- Images
It is therefore no wonder that Hello world9
\documentclass{article}% Hello world 9
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\begin{document}
\noindent%
\includegraphics[width=\linewidth]{tiger}% http://mirrors.ctan.org/info/examples/lgc2/pstricks/tiger.eps
\end{document}
increases the starting PDF objects tally by about a handful (to 17). Other objects include document pages.
( ) named destinations out of ( )
Destination in a PDF refer to marked locations. These are typically associated with sectioning macros like \section{...}, \phantomsection, \chapter{...} and \caption{...}. Hello world10
\documentclass{article}% Hello world 10
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\begin{document}
\section{Hello world.}
\end{document}
produces 3 named destinations (a unit increment from starting with a clean slate Hello world1 and only including the hyperref package).
( ) words of extra memory for PDF output out of ( )
All the above statistics stems from running TeX Live 2011, with pdfTeX, Version 3.1415926-2.3-1.40.12 and will, almost certainly, differ from other installations (however small or large).