3

I find the automatic line breaking in inline math slightly obscure. Is there a comprehensive summary of where and where not automatic line breaks may occur, what are the penalties, etc.? I suppose that's somewhere in the LaTeX companion or the TeX-book, but where? But I'm also fine with any reference. Also, is it possible to suggest particularly good break points to LaTeX?

Specifically, I am thinking about things like $\{x \in X \mid P(x) \allowbreak\ \text{and}\ \allowbreak Q(x)\}$. Is this correct usage? Probably not.

1 Answer 1

3

It's not at all obscure, as there is a single rule: line breaks can be taken at penalties that might be inserted automatically.

The general rule for line break points is explained in the TeXbook on page 96.

TeX automatically inserts penalties after relation atoms and binary operation atoms. The penalty inserted is, respectively, \relpenalty and \binoppenalty. Default values

\relpenalty=500
\binoppenalty=700

You can manually add a penalty anywhere in a formula; if you do where TeX would automatically add one, it won't add it in the specific case (TeXbook, page 174).

Well, there is actually another rule: such penalties (implicit or explicit) have no consequence if they appear in a subformula, basically between { and } not delimiting an argument or between \left and \right. Subformulas are indivisible (and the spaces in them are “frozen”).

The standard example is $x=\nobreak0$ or, in proper LaTeX, $x=\nolinebreak0$, because the commands insert a penalty worth 10000, that inhibits line breaks.

In other cases you can add a penalty after a comma, for solving the case of a problematic paragraph:

$x_1,\linebreak[0],x_2,\dots,x_n$

(in plain TeX, it would be \allowbreak). TeX, by default, would not break a line after a comma in math mode, as explained above, but the manually inserted penalty allows it.

\documentclass{article}

\begin{document}

\parbox{0pt}{
  $x=y$                         % line break
  $x=\nolinebreak y$            % no line break
  $x+y$                         % line break
  $x+\nolinebreak y$            % no line break
  $x,y$                         % no line break
  $x,\linebreak[0]y$            % line break
  ${x=\linebreak y}$            % no break because of the braces
  $\left(x=\linebreak y\right)$ % no break because of \left and \right
}

\end{document}

enter image description here

Spaces are compressed because of the zero width imposed by \parbox{0pt}, which is only meant for triggering as many line breaks as possible.

In your example, \allowbreak should go before the space, so the latter will be discarded if a line break is actually taken.

1
  • Thank you very much for the comprehensive answer! One last question: do I understand you correctly that after operators and relations are the only places at which LaTeX inserts penalties automatically?
    – Bubaya
    Jan 28, 2023 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .