[Tex/LaTex] \penalty-10000 or \linebreak

line-breaking

What are the practical differences between \penalty-10000 and \linebreak? Do both make \allowbreak redundant?

\documentclass{article}

\begin{document}

Text text text text text. This is a paragraph containing a formula,
\(a + b + c + d \times e\).
% breaks before "c"

Text text text text text. This is a paragraph containing a formula,
\(a + b + c \linebreak + d \times e\).
% breaks after "c"

Text text text text text. This is a paragraph containing a formula,
\(a + b + c \penalty-10000 + d \times e\).
% breaks after "c"

\end{document}

Note that this example is not trying to make a statement about good breakpoints within formulas. Feel free to edit in a better example.

By the way, earlier code in this example had \allowbreak\penalty-10000, which is really redundant nonsense (see e.g. user egreg's answer).

Best Answer

Short answer

\penalty-10000 and \linebreak are very much different from each other. And \allowbreak is very different from both.

Long answer

The macros \nobreak, \allowbreak and \break mean, respectively,

\penalty 10000
\penalty 0
\penalty -10000

They are in LaTeX because they are in Plain TeX and the original LaTeX loaded lplain.tex which was a slightly edited copy of plain.tex. They are documented neither in the LaTeX manual nor in the LaTeX Companion. Actually, \nobreak appears in the index of the latter, with a reference to p. 234, but it's probably a typo for \nopagebreak).

Those macros are included for back compatibility: many old LaTeX documents used Plain TeX programming. However they shouldn't be used in newer documents because they are against LaTeX's guidelines of distinguishing commands that go in horizontal and vertical mode.

The problem with \break is that

abc\break def

and

abc\par\break def

mean two very different things: the first one breaks the line (like \linebreak), the second introduces a page break.

With LaTeX's command \linebreak you'd get a line break in the first case and an error in the second one.

In macros, where the programmer can control precisely the timing, those shortcuts can be handy. However

  • \allowbreak appears only once in the LaTeX kernel, in the definition of \pmod which is copied from plain.tex;

  • \break appears twice, in the definition of \eject (again copied from plain.tex) and in the definition of \@gnewline (part of the code for \\, but in the macro an \ifvmode test is made, so this \break can appear only in horizontal or math mode);

  • \nobreak appears more frequently, but always in controlled situations, where the mode can be predicted; a typical appearance is \if@nobreak\ifvmode\nobreak\fi\fi.

The conclusion is easy: don't use those macros in documents. You're allowed to use them in lower level programming, but you should know what you're doing. Don't blame LaTeX if one of your macros using \break issues a page break rather than a line break.