One is often taught that "\\
causes a line break which is not a paragraph break" and "the variant \\*
additionally prevents a page break".
(I hereby acknowledge user egreg
's admonition that "\\*
should not be used".)
But \\*
often doesn't work! When does \\*
not work? How can one fix this?
The following code produces a footnote example and then a body text example. Note that usage of \\*
within body text is probably more common.
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]\footnote{
no asterisk \\ asterisk \\*
no asterisk \\ asterisk \\*
no asterisk \\ asterisk \\*
no asterisk \\ asterisk \\*
no asterisk \\ asterisk \\*
% the pagebreak happens here
last line}
\lipsum[5]
\lipsum[6-8]
\lipsum[2]
Line 1 \\*
% the pagebreak happens here
Line 2 \\*
Line 3 \\*
Line 4 \\*
Line 5 \\
Line 6
\end{document}
Best Answer
Theory
\\*
throws an error if used in vertical mode; in horizontal mode it does the following actions:Thus it looks as if there was a
\nobreak
in vertical mode between the two lines that prevents a page break.However, what happens if TeX puts the lines of a paragraph in the vertical list?
It inserts interline glue between the boxes (depending on the values of
\baselineskip
,\lineskiplimit
, and\lineskip
). Glue after a non-discardable item would constitute a break point.Therefore TeX adds a penalty before the interline glue to control the page breaks. This penalty is
\interlinepenalty
plus some other penalties depending on the context (\clubpenalty
,\widowpenalty
,\displaywidowpenalty
,\brokenpenalty
). Then the break point is this penalty, not the interline glue.The penalty added via
\vadjust
is put right after the current line before the interline penalty and interline glue. Thus we have:Thus we have a break point if the interline penalty is smaller than 10000, despite using
\\*
. If the interline penalty is 10000 or greater, then we do not have a break point anyway with an additional\nobreak
of\\*
or without.However, there is one case where
\\*
actually prevents a line break. Namely "The TeXbook" is not always telling the truth: There is a situation, where TeX does not add a interline glue. It tries to be clever and rationalizes an interlinepenalty of value zero. It probably thinks: interline glue after\hbox
– we have a break point; penalty of zero – neither good nor bad, since there is already a break point, we do not need it. In appendix A in answer to exercise 14.26 can be found:Then
\nobreak
of\\*
kicks in:Voila, the page break is surprisingly prevented. Of course this over-optimization is not a "bug" (TeX is per definition bug-free, de facto), let's call it a "design misfeature". ;-)
For illustration, an example for ini-TeX (or plain TeX) for experimenting/studying. Macro
\NPB
simulates\\*
:Console output:
The stuff between the first lines/
\hbox
es:The first penalty comes from
\vadjust{\penalty10000}
. The interline penalty sums up to zero:\interlinepenalty
+\clubpenalty
= 1 - 1 = 0In the second case:
the interline penalty is not suppressed:
\interlinepenalty
+\widowpenalty
= 1 + 150 = 151. This penalty allows a page break at this place.Practice
The following part is inherited from this answer to the more specific question variant.
The problem is the automatically inserted
\interlinepenalty
. It is usually smaller than 10000 and allows a page break even if it is preceded by a\nobreak
(=\penalty10000
).The following uses a workaround. Instead of ending the line, the paragraph is ended. Then the effects of
\parskip
and\parindent
need to be reversed and avoided:However, this is still a workaround and does not provide a correct implementation for
\\*
. By splitting a paragraph in two paragraphs, up to two interline penalties for the line break before and after the inserted\par
are increased by\widowpenalty
or\clubpenalty
. That is, additional page breaks can be forbidden as a side effect, if the addition by\widowpenalty
or\clubpenalty
now increases the interline penalty to 10000.The other case is less problematic: If the line break, where the
\par
gets inserted, would have get\clubpenalty
or\widowpenalty
, then this penalty is now lost. But since we forbid a page break already by\nobreak
, a loss of an additional penalty does not matter.