# Debugging Advice: TeX Capacity Exceeded with TeXLive2011 (but not with TeXLive2010)

I have a feeling that this is going to be rather embarrassing when I eventually get to the bottom of this problem, but since I have been struggling with this for some time I am posting this question that is more about advice on debugging a problem rather than a specific code fix.

Sadly I have not able to come up with a proper MWE that reproduces the problem. This is the closest I have been able to get after unwrapping all my macros. Am hoping that there are some clues here that might help shed some light as to where I should be looking.

## Background:

This original (complete) version of this figure, and associated text compiled fine as a standalone file with TeXLive2010 and produced the 6 graphs as desired. However, I was not able to successfully incorporate this standalone file in a larger document (> 100 pages). At that time, I attempted to produce a MWE, but was only able to reduce it to a complex collection of figures in a specific order (ie, changing just the order or the figures seems to produce results, yet a different order would terminate with error -- I think they were TeX Capacity related errors as well). As this MWE was very large I did not post it here, and thought I would wait until TeXLive2011 was ready. So as a work around I continued with this one collection of figures not in my document. This was quite some time ago, and much of my code has changed so not sure if this current form would still exhibit that behavior with the large document with TeXLive2010.

Now, with TeXLive2011 it seems I can reproduce the problems with just this one figure being used 6 times. Removing any one of these instances produces the output, so all 6 are required for me to be able to reproduce the problem.

## Summary of Code:

The code given below compiles as provided and produces 6 graphs with both TeXLive2010 and TeXLive2011 (updated as of mid Oct 2011).

The file 01R28-Fig.tex is a standalone file that graphs the following functions (the colors here correspond to the colors of the graphs):

The main file uses the standalone figure twice (two different domains) for three values of a={3,4,5} and adjusts the values of xmin, xmax, etc. There is some code in here that should really have absolutely no effect. I left this in as this is what my macros would have included, and removing some of these sort of alleviates the issues. For instance each path is labelled using name path global=. Since I removed the portion of the code that accessed the paths this should really not have an effect, but it does. Also minor things such as changing the color has a dramatic effect.

Ok, so if this code compiles, what exactly is the problem? Well, if I uncomment the \usepackages{MyPackages} I run into problems. This file contains not only the packages that I include but all my macros and other setup information. Unfortunately, I have not been able to reduce the contents of MyPackages to something that could be posted.

I have attempted to reduce the code from MyPackages by removing what wasn't needed. Really, none of it is needed here (as this MWE compiles), but with it included I get TeX Capacity exceeded. If I attempt to copy and paste it into this file, the problems go away. If I comment out seemly unrelated pieces of code within the files that are included by MyPackages, things seem to work. To me this is an indication of some memory corruption, so am wondering what else I should try...

The only TeXLive2011 specific thing I am aware of in MyPackages is that I needed to add a \ifdefined\newmdenv (in order to be able to run this with TeXLive2010) as that appears to only be available with TeXLive2011.

Following \usepackage{MyPackages}, I have included several \def commands which can be used to enable/disable potions of the code .

## TeXLive2010: (with \usepackage{MyPackages} uncommented):

Now, this MWE as posted here works just fine with both TeXLive2010 and TeXLive2011 releases. But with the MyPackages included I get the following behavior:

With TeXLive2010, I do get the desired output after several errors (and hitting RETURN after each). In an attempt to make this somewhat readable, I have included these error messages in the Appendix A below.

This seems to be a problem with enumitem, but the lists in this file seem pretty basic so don't understand how something in the preamble could have an effect. But nonetheless, I do get the proper output with TeXLive2010. Also, if I re-run (leaving the .aux files), I get the same messages (except for the "rerunfilecheck Warning" no longer showing up).

## TeXLive2011: (with \usepackage{MyPackages} uncommented):

But, when I switch to using TeXLive2011 things go bizarre. First time (ie, after removing any .aux files) I run it I get a fatal error:

./01R28-Fig.tex:138: TeX capacity exceeded, sorry [main memory size=3000000].
\unhbox
l.138 \end{tikzpicture}

./01R28-Fig.tex:138:  ==> Fatal error occurred, no output PDF file produced!
Transcript written on 01R28-V6.log.


and no ouptput is produced. But I do obtain the desired output as follows:

• Upon a subsequent run (with the .aux files left as produced by the fatal error above), I do get the desired output after several errors similar, but different to those produced by TeXLive2010. I have included these error messages in the Appendix B below.

All the subsequent items below also do require me to skip past these errors, and all are initial runs (with any .aux files removed).

• If I change just the two instances of violet to red for GraphF, I do get the desired output. What could I possibly do in the preamble that a minor color change would result in a drastically different results?

• Using \def\NumOfSamples{400} instead of 500, I do get the desired results.

• The only effect of commenting \def\SuppressSpuriousNode{}, has on the code is that this \node at (axis cs: 2,4) [cyan] {\GraphLabelF}; gets added. Again, with this commented out, I do get the desired results.

• Each of the three graphs and the two axis are labelled via name path global. Commenting out any one of the following which removes the names path global:

1. \def\AddNamePathOfAxis{} which removes the name path global from both axis,
2. \def\AddNamePathOfGraphF{}
3. \def\AddNamePathOfGraphG{}

also results in the file producing the desired output.

• Disabling any one of the figures by commenting out \def\ShowFigureA{}...\def\ShowFigureF{} again produces the desired output.

Disabling all six figures still produces the enumitem errors and yields:

This is to illustrate why I have not been able to minimize the content in MyPackages. In one of the files that MyPackages includes I have this macro:

\newcommand{\KERN}{}


If I comment this line, I get the desired output. This macro is only used in an environment that is not used in this document and the command really can't do much besides add a single space in the worst case, yet it drastically alters the behavior.

Any ideas as to where I should look?

if you really want to solve a code problem, what should I have in the MyPackages that could duplicate some this behavior? :-) The change in color is the most perplexing one to me. And yes the lines do show in red.

Here is the code:

\RequirePackage{etoolbox}
\documentclass{standalone}

\usepackage{standalone}
\usepackage[shortlabels]{enumitem}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{pgfplots}
\usetikzlibrary{calc,intersections}%
\usepackage{filecontents}

%\usepackage{MyPackages}% The problem is in here somewhere

\def\NumOfSamples{500}% Compiles with 100,200,300, or 400

\def\ShowFigureA{}% These control which of the 6 figures are drawn.
\def\ShowFigureB{}% Commenting out any of these results (i.e.,
\def\ShowFigureC{}% disabling a figure), results in the desired
\def\ShowFigureD{}% output being produced.
\def\ShowFigureE{}%
\def\ShowFigureF{}%

\def\SuppressSpuriousNode{}%  Compiles if ANY of these are

%%-----------------------------------------------------------------
%%-----------------------------------------------------------------
%%-----------------------------------------------------------------

\begin{filecontents}{01R28-Fig.tex}
\documentclass{standalone}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{pgfplots}
\usetikzlibrary{calc,intersections}%

\begin{document}
\providecommand*{\A}{3}%
\providecommand*{\NumOfSamples}{500}%

\pgfmathdeclarefunction{log}{2}{\pgfmathparse{ln(#2)/ln(#1)}}% log_#2 (#1)

\pgfmathdeclarefunction{GivenF}{1}{\pgfmathparse{(#1)^(\A)}}
\pgfmathdeclarefunction{GivenG}{1}{\pgfmathparse{(\A)^(#1)}}
\pgfmathdeclarefunction{GivenH}{1}{\pgfmathparse{log(\A,(#1))}}

\NewDocumentCommand{\GraphFunction}%
{O{Style_w} O{Style_w} m m m g}{%
% [GraphStyle] [LabelStyle] {x-min}{x-max} {f(x)} {<label>}
mark=none,
domain=#3:#4,
#1
]
({x},{#5})
node [#2] {#6}
;
}

\begin{tikzpicture}
%--------------------------------------------------------------
% These are only needed for this file to be compilable standalone
% These are to be set prior to including this figure to customize this
\providecommand*{\XAxisMin}{-1.0}
\providecommand*{\XAxisMax}{3.0}
\providecommand*{\YAxisMin}{-2.0}
\providecommand*{\YAxisMax}{10}

\providecommand*{\DomainMinF}{\XAxisMin}
\providecommand*{\DomainMaxF}{2.2}

\providecommand*{\DomainMinG}{\XAxisMin}
\providecommand*{\DomainMaxG}{2.1}

\providecommand*{\DomainMinH}{0.1}
\providecommand*{\DomainMaxH}{\XAxisMax}

%--------------------------------------------------------------

\newcommand*{\GraphLabelF}{$y = x^{\A}$}
\newcommand*{\GraphLabelG}{$y = \A^x$}
\newcommand*{\GraphLabelH}{$y = \log_{\A} x$}

\begin{axis}[xmin=\XAxisMin, xmax=\XAxisMax, ymin=\YAxisMin, ymax=\YAxisMax]

%^^^^^^^^^^^^^^^^^^^^^^^^^%
% Compiles if \AddNamePathOfAxis is supressed:
%     i.e., the name path global settings are disabled.
%^^^^^^^^^^^^^^^^^^^^^^^^^%
\tikzstyle{XAxisNameStyle}=[name path global=XAxisPath]% Craps out with
\tikzstyle{YAxisNameStyle}=[name path global=YAxisPath]% these settings
\else
\tikzstyle{XAxisNameStyle}=[]%  Compiles with these settings
\tikzstyle{YAxisNameStyle}=[]%  i.e., axis are not named
\fi

\addplot [% Name the x axis
XAxisNameStyle,
gray, thick
]
coordinates{(\XAxisMin,0.0) (\XAxisMax,0.0)};

YAxisNameStyle,
gray, thick
]
coordinates{(0,\YAxisMin) (0,\YAxisMax)};

%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%
% Compiles if we disable the name path global setting for GraphF
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%
\ifdefined\AddNamePathOfGraphF% Craps out with these settings
\tikzstyle{GraphFNameStyle}=[name path global=GraphF]%
\else%                          Compiles with these settings
\tikzstyle{GraphFNameStyle}=[]%
\fi

\GraphFunction[smooth, violet, very thick,
GraphFNameStyle,% Bizarre: Need comma or % here
]
[violet, right]
{\DomainMaxF}{\DomainMinF}
{GivenF(x)}{\GraphLabelF}

%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%
\ifdefined\SuppressSpuriousNode% Compiles if this is node is suppressed
\else
\node at (axis cs: 2,4) [cyan]  {\GraphLabelF};
\fi
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%

%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%
% Compiles if we disable the name path global setting for GraphG
%^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^%
\ifdefined\AddNamePathOfGraphG%  Craps out with these settings
\tikzstyle{GraphGNameStyle}=[name path global=GraphG]%
\else%                           Compiles with these settings
\tikzstyle{GraphGNameStyle}=[]%
\fi

\GraphFunction[smooth, orange, very thick,
GraphGNameStyle,% Bizarre: Need comma or % here
]
[orange, above right]
{\DomainMaxG}{\DomainMinG}
{GivenG(x)}{\GraphLabelG}

\GraphFunction
[smooth, magenta, very thick]
[magenta, above right, xshift=1.5ex]
{\DomainMaxH}{\DomainMinH}
{GivenH(x)}{\GraphLabelH}

\end{axis}
\end{tikzpicture}
\end{document}
\end{filecontents}% 01R28-Fig

%%-----------------------------------------------------------------
%%-----------------------------------------------------------------
%%-----------------------------------------------------------------

\usepackage{standalone}
\usepackage[shortlabels]{enumitem}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{pgfplots}
\usetikzlibrary{calc,intersections}%
\usepackage{filecontents}

\newcommand*{\InsertFigure}{\input{01R28-Fig}}

\begin{document}
\begin{enumerate}[(i)]
\item $a=3$

{% Group to keep settings local
\newcommand*{\A}{3}

\ifdefined\ShowFigureA
\begin{minipage}{0.90\linewidth}
\pgfmathsetmacro{\XAxisMin}{-1.8}
\pgfmathsetmacro{\XAxisMax}{3.5}
\pgfmathsetmacro{\YAxisMin}{-5.0}
\pgfmathsetmacro{\YAxisMax}{50}

\pgfmathsetmacro{\DomainMinF}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxF}{\XAxisMax}
\pgfmathsetmacro{\DomainMinG}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxG}{\XAxisMax}
\pgfmathsetmacro{\DomainMinH}{0.001}
\pgfmathsetmacro{\DomainMaxH}{\XAxisMax}

\pgfplotsset{
width=0.80\linewidth, height=6.0cm,
xtick={-1,0,1,2,3}, scale only axis,
ytick={0,10,...,40},
yticklabel style={text width=\widthof{$-20$},align=right},
xticklabel style={text width=\widthof{$2.4$},align=center}
}
\InsertFigure
\end{minipage}
\fi% end \ifdefined\ShowFigureA

\ifdefined\ShowFigureB
\bigskip
\begin{minipage}{0.90\linewidth}
\pgfmathsetmacro{\XAxisMin}{2.4}
\pgfmathsetmacro{\XAxisMax}{3.1}
\pgfmathsetmacro{\YAxisMin}{12.0}
\pgfmathsetmacro{\YAxisMax}{30.0}

\pgfmathsetmacro{\DomainMinF}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxF}{\XAxisMax}
\pgfmathsetmacro{\DomainMinG}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxG}{\XAxisMax}
\pgfmathsetmacro{\DomainMinH}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxH}{\XAxisMax}

\pgfplotsset{
width=0.80\linewidth, height=6.0cm,
xtick={2.5,2.6,2.7,2.8,2.9,3.0}, scale only axis,
ytick={15,20,25},
yticklabel style={text width=\widthof{$-20$},align=right},
xticklabel style={text width=\widthof{$2.4$},align=center}
}

\InsertFigure
\end{minipage}
\fi% end \ifdefined\ShowFigureB
}
%-----------------------------------------------------------

\bigskip
\item $a=4$

{% Group to keep settings local
\newcommand*{\A}{4}

\ifdefined\ShowFigureC
\begin{minipage}{0.90\linewidth}
\pgfmathsetmacro{\XAxisMin}{-1.5}
\pgfmathsetmacro{\XAxisMax}{1.5}
\pgfmathsetmacro{\YAxisMin}{-0.5}
\pgfmathsetmacro{\YAxisMax}{4}

\pgfmathsetmacro{\DomainMinF}{-1.45}
\pgfmathsetmacro{\DomainMaxF}{2.2}
\pgfmathsetmacro{\DomainMinG}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxG}{2.2}
\pgfmathsetmacro{\DomainMinH}{0.5}
\pgfmathsetmacro{\DomainMaxH}{\XAxisMax}

\pgfplotsset{
width=0.85\linewidth, height=6.0cm,
xtick={-1.0,-0.5,0,0.5,1.0}, scale only axis,
ytick={0,1,2,3},
yticklabel style={text width=\widthof{$400$},align=right},
xticklabel style={text width=\widthof{$-4.5$},align=center}
}
\InsertFigure
\end{minipage}
\fi% end \ifdefined\ShowFigureC

\ifdefined\ShowFigureD
\bigskip
\begin{minipage}{0.90\linewidth}
\pgfmathsetmacro{\XAxisMin}{1.5}
\pgfmathsetmacro{\XAxisMax}{4.5}
\pgfmathsetmacro{\YAxisMin}{0}
\pgfmathsetmacro{\YAxisMax}{400}

\pgfmathsetmacro{\DomainMinF}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxF}{4.5}
\pgfmathsetmacro{\DomainMinG}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxG}{4.4}
\pgfmathsetmacro{\DomainMinH}{5.0}% Won't plot H here, since this
\pgfmathsetmacro{\DomainMaxH}{5.1}% is beyond \XAxisMax

\pgfplotsset{
width=0.85\linewidth, height=6.0cm,
xtick={2.0,2.5,3.0,3.5,4.0}, scale only axis,
ytick={0,100,200,300},
yticklabel style={text width=\widthof{$400$},align=right},
xticklabel style={text width=\widthof{$4.5$},align=center}
}
\InsertFigure
\end{minipage}
\fi% end \ifdefined\ShowFigureD
}

%-----------------------------------------------------------
\bigskip
\item $a=5$

{% Group to keep settings local
\newcommand*{\A}{5}%

\ifdefined\ShowFigureE
\begin{minipage}{0.90\linewidth}
\pgfmathsetmacro{\XAxisMin}{-1.5}
\pgfmathsetmacro{\XAxisMax}{2.5}
\pgfmathsetmacro{\YAxisMin}{-5}
\pgfmathsetmacro{\YAxisMax}{25}

\pgfmathsetmacro{\DomainMinF}{-1.4}
\pgfmathsetmacro{\DomainMaxF}{2.2}
\pgfmathsetmacro{\DomainMinG}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxG}{2.2}
\pgfmathsetmacro{\DomainMinH}{0.0001}
\pgfmathsetmacro{\DomainMaxH}{\XAxisMax}

\pgfplotsset{
width=0.80\linewidth, height=6.0cm,
xtick={-1,0,1,2,3}, scale only axis,
yticklabel style={text width=\widthof{$3,400$},align=right},
xticklabel style={text width=\widthof{$-5.00$},align=center}
}
\InsertFigure
\end{minipage}
\fi% end \ifdefined\ShowFigureE

\ifdefined\ShowFigureF
\bigskip
\begin{minipage}{0.90\linewidth}
\pgfmathsetmacro{\XAxisMin}{4.95}
\pgfmathsetmacro{\XAxisMax}{5.05}
\pgfmathsetmacro{\YAxisMin}{2800}
\pgfmathsetmacro{\YAxisMax}{3400}

\pgfmathsetmacro{\DomainMinF}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxF}{\XAxisMax}
\pgfmathsetmacro{\DomainMinG}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxG}{\XAxisMax}
\pgfmathsetmacro{\DomainMinH}{\XAxisMin}
\pgfmathsetmacro{\DomainMaxH}{\XAxisMax}

\pgfplotsset{
width=0.80\linewidth, height=6.0cm,
xtick={4.95,5.00,5.05}, scale only axis,
yticklabel style={text width=\widthof{$3,400$},align=right},
xticklabel style={text width=\widthof{$5.00$},align=center}
}
\InsertFigure
\end{minipage}
\fi% end \ifdefined\ShowFigureF
}
\end{enumerate}
\end{document}


## Appendix A: TeXLive2010 enumitem errors

(/usr/local/texlive/2010/texmf-dist/tex/latex/microtype/mt-eur.cfg)
(./01R28-Fig.tex) (./01R28-Fig.tex) (./01R28-Fig.tex) (./01R28-Fig.tex)
(./01R28-Fig.tex) (./01R28-Fig.tex)
./01R28-V6.tex:364: Undefined control sequence.
\enit@endenumerate ->\enit@after
\endlist \enit@toks \expandafter {\enit@sav...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
\enit@endenumerate ...expandafter {\enit@savekeys
}\xdef \enit@afterlist {\d...
l.364 \end{enumerate}

?
Preview: Tightpage -32891 -32891 32891 32891
[1{/usr/local/texlive/2010/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./01R28-V6.aux)

>Package rerunfilecheck Warning: File 01R28-V6.out' has changed.
(rerunfilecheck)                Rerun to get outlines right
(rerunfilecheck)                or use package bookmark'.


## Appendix B: TeXLive2011 enumitem errors

./01R28-Fig.tex) (./01R28-Fig.tex) (./01R28-Fig.tex) (./01R28-Fig.tex)
(./01R28-Fig.tex) (./01R28-Fig.tex)
./01R28-V6.tex:364: Undefined control sequence.
\enit@endenumerate ->\enit@after
\endlist \ifx \enit@series \relax \else \if...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
\enit@endenumerate ...\else \ifnum \enit@resuming
=\@ne \enit@setresumekeys ...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Missing number, treated as zero.
=
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
\enit@setresumekeys ...xpandafter {\enit@savekeys
}\xdef \enit@afterlist {#2...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
\enit@setresumekeys ...it@toks }\ifnum \enit@type
=\z@ #3\def \enit@noexcs {...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Missing number, treated as zero.
=
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
<argument> enit@resume@series@\enit@series

l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
\enit@endenumerate ...t \fi \ifnum \enit@resuming
=\thr@@ \enit@setresumekey...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Missing number, treated as zero.
=
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
\enit@setresumekeys ...xpandafter {\enit@savekeys
}\xdef \enit@afterlist {#2...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Undefined control sequence.
\enit@setresumekeys ...it@toks }\ifnum \enit@type
=\z@ #3\def \enit@noexcs {...
l.364 \end{enumerate}

?
./01R28-V6.tex:364: Missing number, treated as zero.
=
l.364 \end{enumerate}

?
Preview: Tightpage -32891 -32891 32891 32891
[1{/usr/local/texlive/2011/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./01R28-V6.aux)

-
When compiling with TeXLive 2010 and 2011 and comparing the .log-file, I noticed TeXLive2010: Here is how much of TeX's memory you used: ... strings out of 493747 ... string characters out of 3147494 ... TeXLive2011: Here is how much of TeX's memory you used: ... strings out of 493629 ... string characters out of 3147109 i.e. the available memory in TeXLive 2011 has been (slightly) reduced. I don't really suppose that your document needs some amount in between, therefore this is no answer but only a comment. –  Stephen Nov 11 '11 at 18:52

Well main memory is - to quote the latex companion - the part of TeX in which macro definitions and the material for the current page are stored. ... Exceeding main memory ... can happen if .. you load many packages, have a large number of huge deferred floats or use macro packages that produce new macros on the fly.
You can set \tracingstats=2. TeX will then report the main memory status. ... The number to the left of the & is the memory devoted to large objects, the number on the right the memory used by macro definition.
Regarding your enumitem problem: This sounds like a grouping problem. Definitions set at the start of enumerate are lost at the \end{enumerate}. I would try to put e.g. \makeatletter\show\enit@savekeys at various places to get an idea when the definition changes.