答案1
我不会像 John Kormylo 建议的那样将数学公式括在里面\mbox
,而是定义一个禁止在数学公式中换行的命令。事实上,这允许公式中的粘连可以与同一行上的其他粘连一起拉伸和收缩,而 John 的解决方案则不会。
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\makeatletter
\newcommand*{\prohibitmathbreaks}{%
\binoppenalty \@M
\relpenalty \@M
}
\hyphenpenalty = \@M % ONLY for this example: DO NOT INCLUDE IN YOUR DOCUMENTS!
\makeatother
\begin{document}
Some meaningless text, inserted just to get near\ldots\ the end of the line.
\( x+y=a+b\prohibitmathbreaks \).
And some more random text that adds other lines, which~contain~an unbreakable
sequence of words, to show that the spaces inside the formula \emph{are} allowed
to shrink.
On the other hand, if one uses the \verb|\mbox| solution, this does not happen:
\mbox{\( x+y=a+b \).}
And: some more random text that adds other lines, which~contain
unbreakable~sequences~of~words.
Another paragraph, containing another formula, in order to show that the effect
of our \verb|\prohibitmathbreaks| command is kept local:
\( a+b+c+d+e = x+y+z \).
\end{document}
输出: