# Tex capacity exceeded compiling only 50 lines latex file (pdftex), seg. fault (lualatex)

This is one of the strangest things I've seen in Latex (and I have seen many strange things). 50 lines of code, almost all of it is verbatim.

Any small change to the verbatim can cause the error to go away. it seems random. I managed to get it to 50 lines verbatim and still show the error. But if I make small change, remove 2-3 lines or delete an empty line, the error could go away or it might stay. it is random. Here is the code:

\documentclass[11pt]{book}%ext
\usepackage[T1]{fontenc}
\usepackage{verbatim}
\usepackage{amsmath,mathtools}
\usepackage[utf8]{inputenc} %DO NOT USE WIT LUALATEX, only with pdflatex
\usepackage{graphicx}
\usepackage{breqn}   %do not use this with tex4ht.  added 4/2/16

\begin{document}
\section{How to implement Steepest descent for finding minumum of $f(x,y)$ ?}

\begin{verbatim}

function nma_problem_2()
close all;
del      = 0.05;
u1       = 0:del:20;
u2       = -10:del:15;
[u1,u2]  = meshgrid(u1,u2);

plot(0,0);
xlim([0 20]); ylim([-5 15]);
hold on;
[u(1),u(2)] = ginput(1);
t=text(1.08*u(1),u(2),sprintf('[%2.1f,%2.1f]',u(1),u(2)));
t.FontSize=8;
t.Color='red';
x = fminsearch(@objectiveFunc, u); %used to find the minumum in order to show
%progress towards it
hold on;
plot(x(1),x(2),'*r')
plot(u(1),u(2),'or')

MAX_ITER = 50;
REL_TOL  = 10^(-4);
stepSize = -1; %optimal
[p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL,stepSize,...
[C,h]    = contour(u1,u2,z,levelSets); %,'ShowText','on');

if length(p(:,1))>1
for k=1:length(p)-1
line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line between each step
drawnow;
pause(.2);
title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f,  step = %d',...
u(1),u(2),norm(objectiveFunc(u)),k));
end
end
\end{verbatim}
\end{document}


Please make sure not to modify the code before seeing the error, as any small change to the verbatim code, could mask the error away! I also put the above source as in this folder

Here is the error

pwd
/media/data/latex/standalone_2

pdflatex foo.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./foo.tex
LaTeX2e <2015/10/01> patch level 2
Babel <3.9m> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/book.cls
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/bk11.clo))
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1enc.def))
(/usr/local/texlive/2015/texmf-dist/tex/latex/fancybox/fancybox.sty
Style option: fancybox' v1.4 <2010/05/15> (tvz)
) (/usr/local/texlive/2015/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
Style option: fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix
<2008/02/07> (tvz)
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/keyval.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the ?' option.
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mathtools.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mhsetup.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/inputenc.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/utf8.def
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1enc.dfu)
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/ot1enc.dfu)
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/omsenc.dfu)))
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(/usr/local/texlive/2015/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/breqn.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/flexisym.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/cmbase.sym)
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/mathstyle.sty))) (./foo.aux
) (/usr/local/texlive/2015/texmf-dist/tex/context/base/supp-pdf.mkii
) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1cmtt.fd)
Overfull \hbox (75.69456pt too wide) in paragraph at lines 50--50
[]\T1/cmtt/m/n/10.95 x = fminsearch(@objectiveFunc, u); %used to find the minum
um in order to show[]

Overfull \hbox (30.4276pt too wide) in paragraph at lines 50--50
[]\T1/cmtt/m/n/10.95 [p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL,s
tepSize,...[]

Overfull \hbox (41.74434pt too wide) in paragraph at lines 50--50
[]\T1/cmtt/m/n/10.95 line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line betw
een each step[]

Overfull \hbox (41.74434pt too wide) in paragraph at lines 50--50
[]\T1/cmtt/m/n/10.95 title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f,  s
tep = %d',...[]

Underfull \vbox (badness 10000) has occurred while \output is active
! TeX capacity exceeded, sorry [main memory size=8000000].
,->\leavevmode \kern \z@
\char \,
l.50 \end{verbatim}

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


This that will go the error to go away:

change the line \section{How to implement Steepest descent for finding minumum of $f(x,y)$ ?} to \section{How to implement Steepest descent for finding minumum of f ?}

also delete the empty line after verbatim i.e. change

\begin{verbatim}

function nma_problem_2()


to

\begin{verbatim}
function nma_problem_2()


also remove the breqn package will remove the error.

And many other little things like this. The error can go away by random. May be it is breqn fault again, I do not know.

question is: How to resolve this error? What is causing it?

TL 2015 on Linux. Error also shows on windows under miktex.

btw, lualatex core dumps on this file also

standalone_2>lualatex foo.tex
This is LuaTeX, Version beta-0.80.0.1 (TeX Live 2015) (rev 5863)
restricted \write18 enabled.
(./foo.tex
LaTeX2e <2015/10/01> patch level 2
Babel <3.9m> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/book.cls
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/bk11.clo))
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/fontenc.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1enc.def))
(/usr/local/texlive/2015/texmf-dist/tex/latex/tools/verbatim.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the ?' option.
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mathtools.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/tools/calc.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mhsetup.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/inputenc.sty

Package inputenc Warning: inputenc package ignored with utf8 based engines.

) (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(/usr/local/texlive/2015/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/breqn.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/l3pdfmode.def))
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/flexisym.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/cmbase.sym)
(/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/mathstyle.sty))) (./foo.aux
) (/usr/local/texlive/2015/texmf-dist/tex/context/base/supp-pdf.mkii
) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2015/texmf-dist/scripts/oberdiek/oberdiek.luatex.lua)))
(/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1cmtt.fd)
Overfull \hbox (75.69456pt too wide) in paragraph at lines 28--28
[][]\T1/cmtt/m/n/10.95 x = fminsearch(@objectiveFunc, u); %used to find the min
umum in order to show[]

Overfull \hbox (30.4276pt too wide) in paragraph at lines 37--37
[][]\T1/cmtt/m/n/10.95 [p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL
,stepSize,...[]

Overfull \hbox (41.74434pt too wide) in paragraph at lines 43--43
[][]\T1/cmtt/m/n/10.95 line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line be
tween each step[]

Overfull \hbox (41.74434pt too wide) in paragraph at lines 46--46
[][]\T1/cmtt/m/n/10.95 title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f,
step = %d',...[]

Underfull \vbox (badness 10000) has occurred while \output is active
! TeX capacity exceeded, sorry [node memory size=385258750].
,->\leavevmode \kern \z@
\char \,
l.49    end

Segmentation fault

• Of course the issue is due to breqn. – egreg May 20 '16 at 11:20
• I have to use breqn it is all over my code, but I also need to use verbatim. Why would breqn has anything to do with verbatim? – Nasser May 20 '16 at 11:26
• @DavidCarlisle: It crashes for me in TL16 (but not in TL15). I will look into it and try to minimize it. – Ulrike Fischer May 20 '16 at 11:44
• Three things appear to be needed: i) breqn must be loaded; ii) there must be a comma in math mode in the section heading and iii) the verbatim has to be long enough to break to the next page. (Edit: for the capacity problem, tested with pdflatex, TL15.) – Torbjørn T. May 20 '16 at 11:46
• Fixed in experimental. – Luigi Scarso May 20 '16 at 16:23

The error is due to breqn, of course. Only one definition for an active character can be valid at a given time.

Since you have a math comma in the section title, this goes in the header and, with that long verbatim, it gets typeset when verbatim is active, which gives a different meaning to the active comma.

Here's a minimal example showing the issue.

\documentclass[11pt]{book}
\usepackage{breqn}

\setlength{\textheight}{2cm} % to shorten the input

\begin{document}
\section{$f(x,y)$}

\begin{verbatim}
x
x
x
x
x
\end{verbatim}
\end{document}


Here's a fix to \do@noligs, which is responsible for defining a new meaning for active characters in verbatim.

\documentclass[11pt]{book}
\usepackage{breqn}

\makeatletter
\def\do@noligs#1{%
\catcode#1\active
\begingroup\lccode\~#1\relax
\lowercase{\endgroup
\ifdefined~%
\expandafter\def\expandafter~\expandafter{%
\expandafter\relax
\expandafter\ifmmode
~% in math mode use the meaning given by breqn
\else
\leavevmode\kern\z@\char#1\relax
\fi
}%
\else
\def~{\leavevmode\kern\z@\char#1}%
\fi
}%
}
\makeatother

\setlength{\textheight}{2cm}

\begin{document}
\section{$f(x,y)$}

\begin{verbatim}
x
x
x
x
x
\end{verbatim}
\end{document}


The main problem is the breqn math comma being written to the mark used in headings while verbatim is active. which gives a classic fragile command in moving argument cryptic error. \hbox hides this (a better fix allowing the comma to be used normally may be posted later)

The fact that luatex segfaults after the runaway argument is a separate lower level bug (or not a bug). The code uses arbitrary amounts of memory as it is in an infinite loop, so in classic tex it hits a hard limit but luatex just allocates more and more memory until it runs out of memory of your actual hardware.

\documentclass[11pt]{book}%ext
\usepackage[T1]{fontenc}
\usepackage{verbatim}
\usepackage{amsmath,mathtools}
\usepackage[utf8]{inputenc} %DO NOT USE WIT LUALATEX, only with pdflatex
\usepackage{graphicx}
\usepackage{breqn}   %do not use this with tex4ht.  added 4/2/16

\begin{document}

\section{How to implement Steepest descent for finding minumum of  $f(x\hbox{,}y)$ ?}

\begin{verbatim}

function nma_problem_2()
close all;
del      = 0.05;
u1       = 0:del:20;
u2       = -10:del:15;
[u1,u2]  = meshgrid(u1,u2);

plot(0,0);
xlim([0 20]); ylim([-5 15]);
hold on;
[u(1),u(2)] = ginput(1);
t=text(1.08*u(1),u(2),sprintf('[%2.1f,%2.1f]',u(1),u(2)));
t.FontSize=8;
t.Color='red';
x = fminsearch(@objectiveFunc, u); %used to find the minumum in order to show
%progress towards it
hold on;
plot(x(1),x(2),'*r')
plot(u(1),u(2),'or')

MAX_ITER = 50;
REL_TOL  = 10^(-4);
stepSize = -1; %optimal
[p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL,stepSize,...
[C,h]    = contour(u1,u2,z,levelSets); %,'ShowText','on');

if length(p(:,1))>1
for k=1:length(p)-1
line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line between each step
drawnow;
pause(.2);
title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f,  step = %d',...
u(1),u(2),norm(objectiveFunc(u)),k));
end
end
\end{verbatim}

\end{document}
`
• @TorbjørnT. sorry that was a leftover from debugging (actually I saw your comment above after posting this you'd reached same conclusion i wouldn't have posted had I seen it:-) – David Carlisle May 20 '16 at 12:03
• @TorbjørnT. answer works now. (no time to patch the headings to make comma safe just now) – David Carlisle May 20 '16 at 12:17