Tex 容量超出,仅编译 50 行 latex 文件 (pdftex),分段错误 (lualatex)

Tex 容量超出,仅编译 50 行 latex 文件 (pdftex),分段错误 (lualatex)

这是我在 Latex 中见过的最奇怪的事情之一(我见过很多奇怪的事情)。50 行代码,几乎全部都是verbatim

对逐字的任何微小更改都可能导致错误消失。它似乎是随机的。我设法将其逐字改为 50 行,但仍然显示错误。但如果我进行微小更改,删除 2-3 行或删除一个空行,错误可能会消失或可能保留。它是随机的。以下是代码:

\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,...
    @objectiveFunc,@gradientFunc);
    [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}

请确保在看到错误之前不要修改代码,因为对verbatim都可能掩盖错误!我还把上面的源代码放成了在此文件夹中

这是错误

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
[Loading MPS to PDF converter (version 2006.09.02).]
) (/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>

这将使错误消失:

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

verbatim也删除ie 更改后的空行

\begin{verbatim}

    function nma_problem_2()

\begin{verbatim}
    function nma_problem_2()

删除该breqn包也会消除错误。

还有许多其他类似的小事。错误可能会随机消失。也许又是breqn错误,我不知道。

问题是:如何解决此错误?是什么原因造成的?

Linux 上的 TL 2015。在 miktex 下的 Windows 上也显示错误。

顺便提一句,lualatex 核心转储在此文件上

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
[Loading MPS to PDF converter (version 2006.09.02).]
) (/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/generic/oberdiek/luatex-loader.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

答案1

当然,错误是由于 造成的breqn。在给定时间内,活动角色只能有一个定义有效。

由于在章节标题中有一个数学逗号,因此它会进入标题,并且verbatim当它处于活动状态时它会被排版verbatim,这会为活动逗号赋予不同的含义。

这是一个显示该问题的最小例子。

\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}

这里是对 的修复\do@noligs,负责为 中的活动字符定义新的含义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}

答案2

主要问题是,在逐字激活时,breqn 数学逗号被写入标题中使用的标记。这会导致移动参数神秘错误中的经典脆弱命令。\hbox隐藏此问题(稍后可能会发布更好的修复方法,以允许正常使用逗号)

luatex 在 runaway 参数之后发生段错误,这是一个单独的低级错误(或者不是错误)。由于处于无限循环中,代码使用任意数量的内存,因此在经典 tex 中它会达到硬限制,但 luatex 只会分配越来越多的内存,直到耗尽实际硬件的内存。

\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,...
    @objectiveFunc,@gradientFunc);
    [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}

相关内容