在内联数学模式 ( $...$
) 中,如果公式太长,LaTeX 将尝试在运算符上将其分解,例如
very long text followed by a very long equation like $a+b+c+d+e+f+g+h+i+j+k+l$ etc
可以表示为
very long text followed
by a very long equation
like a+b+c+d+e+f+g+h+i+
j+k+l etc
但是,如果它们之间用逗号分隔,则不会发生中断,例如
very long text followed by a very long equation like $a,b,c,d,e,f,g,h,i,j,k,l$ etc
会溢出页面,就像
very long text followed
by a very long equation
like a,b,c,d,e,f,g,h,i,j,k,l
etc
如何让 LaTeX 也能在逗号后插入换行符?
答案1
如果表达式包含许多逗号,则考虑将其拆分为多个数学表达式,并用逗号分隔。它读起来就像数学表达式列表。这样 TeX 就可以换行了。
若要在逗号后实现换行,可\allowbreak
在逗号后和下一个数学符号前插入。如有必要,可在 后留空\allowbreak
。
如果你想要一个文档范围的解决方案,你可以重新定义逗号。一个解决方案是按照提示这里将会:
\makeatletter
\def\old@comma{,}
\catcode`\,=13
\def,{%
\ifmmode%
\old@comma\discretionary{}{}{}%
\else%
\old@comma%
\fi%
}
\makeatother
答案2
你可以看看breqn
包,旨在从一般意义上解决这个问题。
答案3
这是一个不会使逗号全局生效的解决方案:
\documentclass{article}
\newcommand{\splitatcommas}[1]{%
\begingroup
\begingroup\lccode`~=`, \lowercase{\endgroup
\edef~{\mathchar\the\mathcode`, \penalty0 \noexpand\hspace{0pt plus 1em}}%
}\mathcode`,="8000 #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}
\lineskiplimit
和的设置\lineskip
适用于论证中需要分数的特殊情况。
允许嵌套的变体:
\documentclass{article}
\newcommand{\splitatcommas}[1]{%
\begingroup
\ifnum\mathcode`,="8000
\else
\begingroup\lccode`~=`, \lowercase{\endgroup
\edef~{\mathchar\the\mathcode`, \penalty0 \noexpand\hspace{0pt plus 1em}}%
}\mathcode`,="8000
\fi
#1%
\endgroup
}
\newcommand{\tuple}[1]{(\splitatcommas{#1})}
\newcommand{\set}[1]{\{\splitatcommas{#1}\}}
\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}
}$
$\set{
\tuple{a,b,c,d},\tuple{1,2,3,4,5,6},\tuple{11,22,33,44,55,66,77,88},
\tuple{a,b,c,d},\tuple{1,2,3,4,5,6},\tuple{11,22,33,44,55,66,77,88},
\tuple{a,b,c,d},\tuple{1,2,3,4,5,6},\tuple{11,22,33,44,55,66,77,88},
\tuple{a,b,c,d},\tuple{1,2,3,4,5,6},\tuple{11,22,33,44,55,66,77,88}
}$
\end{document}
答案4
在 luatex 中,您有一个不涉及活动字符的新可能性,您可以声明,
为 a mathbin
(like +
),以便允许换行,然后将 mathord-mathbin 间距设置为零,这样它前面就没有空格,就像标点符号一样:
\documentclass{article}
\begin{document}
$
\mathcode`\,="213B % mathbin
\Umathordbinspacing\textstyle 0mu % no space before
a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,
a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a$
\end{document}