12

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).

4
  • 1
    \allowbreak is \penalty0, \linebreak throws an error if used in vertical mode and else without optional argument issues \penalty-10000 (and inserts the last skip if there was one)
    – cgnieder
    Jun 15, 2013 at 8:51
  • This is a duplicate, I'll see if I can find it.... Jun 15, 2013 at 9:10
  • @DavidCarlisle I think the "duplicate" may be my older question which nicely complements this one (questions and answers combined) and asks sort of about an opposite thing. I'd say keep this one, as egreg's answer provides good information. Jun 16, 2013 at 10:17
  • @LoverofStructure I'm sure I've answered this before (but perhaps it was \pagebreak v \penalty1000 (which is similar) but I couldn't find it when I looked last night. Sure we shouldn't close now egreg has answered:-) Jun 16, 2013 at 10:25

1 Answer 1

15

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.

5
  • Okay, but "very much different" might be an exaggeration. My understanding now is that, if one is not in v-mode, they're practically quite similar, even though there are principled reasons to prefer \linebreak. Jun 16, 2013 at 10:20
  • @LoverofStructure It's not an exaggeration. A dark glass bottle containing wine and one containing water look pretty similar; I'd say they're much different when their contents is what we're discussing.
    – egreg
    Jun 16, 2013 at 10:24
  • I disagree: it seems to me more like one is a cable and the other is a cable with shielding (space preservation) and a surge protector (throwing of errors under certain circumstances) built in ;-) You can use the raw cable in more situations. Jun 16, 2013 at 10:35
  • @LoverofStructure Would you give the wine bottle to a thirsty infant? ;-)
    – egreg
    Jun 16, 2013 at 10:47
  • That it doesn't matter whether one feeds you wine or water deeply concerns me, Mr H-Mode ;-) Jun 16, 2013 at 10:50

You must log in to answer this question.

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