我正在尝试使用一个很好的解决方案来解决我遇到的一个问题,即用逗号分隔长数学序列,如下所示允许在内联数学模式下换行只是当我将它放入主代码中时才发现,tex capacity exceeded
而主代码恰好也需要该breqn
包。似乎存在一个超出我理解范围的冲突。当我不使用该包时,解决方案有效breqn
,但我需要这个包。
这是 MWE
\documentclass[11pt]{article}%
\usepackage{breqn} %do not use this with tex4ht.
%code from https://tex.stackexchange.com/questions/1959/allowing-line-break-at-in-inline-math-mode/309558#309558
\makeatletter
\def\old@comma{,}
\catcode`\,=13
\def,{%
\ifmmode%
\old@comma\discretionary{}{}{}%
\else%
\old@comma%
\fi%
}
\makeatother
\begin{document}
$\frac{1}{2},\frac{3}{5},\frac{8}{13},\frac{21}{34},\frac{55}{89},
\frac{144}{233},\frac{377}{610},\frac{987}{1597},\frac{2584}{4181},
\frac{6765}{10946},\frac{17711}{28657},\frac{46368}{75025},
\frac{121393}{196418},\frac{317811}{514229},\frac{832040}{1346269},
\frac{2178309}{3524578},\frac{5702887}{9227465},
\frac{14930352}{24157817},\frac{39088169}{63245986},\frac{102334155}{165580141}
$
\end{document}
然后
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/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2015/texmf-dist/tex/latex/base/size11.clo))
(/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))
(/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2015/texmf-dist/tex/latex/tools/calc.sty)) (./foo.aux)
! TeX capacity exceeded, sorry [input stack size=5000].
,->\ifmmode \old@comma
\discretionary {}{}{}\else \old@comma \fi
l.18 $\frac{1}{2},
\frac{3}{5},\frac{8}{13},\frac{21}{34},\frac{55}{89},
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on foo.log.
日志档案
Here is how much of TeX's memory you used:
7740 strings out of 493054
142814 string characters out of 8884759
167252 words of memory out of 8000000
11311 multiletter control sequences out of 15000+600000
6379 words of font info for 23 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
5000i,3n,40p,10354b,275s stack positions out of 5000i,500n,10000p,30000000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
问题是:我需要做哪些更改才能使上述宏起作用并仍然使用breqn
包?
答案1
由于breqn
所有字符都是数学活跃的,因此该解决方案不起作用;但我们可以利用以下特点breqn
:
\documentclass{article}
\usepackage{breqn}
\newcommand{\splitatcommas}[1]{%
\begingroup
\begingroup\lccode`~=`, \lowercase{\endgroup
\expandafter\def\expandafter~\expandafter{~\penalty0 \hspace{0pt plus 1em}}%
}#1%
\endgroup
}
\begin{document}
\setlength{\lineskiplimit}{2pt}\setlength{\lineskip}{3pt} % for this particular case
$\splitatcommas{
\frac{1}{2},\frac{3}{5},\frac{8}{13},\frac{21}{34},\frac{55}{89},
\frac{144}{233},\frac{377}{610},\frac{987}{1597},\frac{2584}{4181},
\frac{6765}{10946},\frac{17711}{28657},\frac{46368}{75025},
\frac{121393}{196418},\frac{317811}{514229},\frac{832040}{1346269},
\frac{2178309}{3524578},\frac{5702887}{9227465},
\frac{14930352}{24157817},\frac{39088169}{63245986},\frac{102334155}{165580141}
}$
\end{document}