[Tex/LaTex] How do \widowpenalty and \clubpenalty interact for a 2-line paragraph

line-breakingpage-breakingwidows-orphans

Sometimes \\* does not suffice to prevent a linebreak. Adding {\widowpenalty10000 \par} or {\clubpenalty10000 \par} helps if the separated line is paragraph-final and stranded at the top of a page ("widow") or paragraph-initial and stranded at the bottom of a page ("orphan").

Here is an example:

\documentclass{article}

\newcommand*{\twolines}{%
  line 1 \\*
  line 2 \par%
}
\newcommand*{\twolinesInseparable}{%
  line 1 \\*
  line 2 {\widowpenalty10000 \par}%
}

\begin{document}

\vspace*{32\baselineskip}
\twolines\twolines\twolines
\twolines\twolines\twolines
\twolines\twolines\twolines

\newpage

\vspace*{32\baselineskip}
\twolinesInseparable\twolinesInseparable\twolinesInseparable
\twolinesInseparable\twolinesInseparable\twolinesInseparable
\twolinesInseparable\twolinesInseparable\twolinesInseparable

\end{document}

In this code, the linebreak between pages 1 and 2 (\twolines) will split a 2-line chunk (despite the \\*), whereas this doesn't happen between pages 3 and 4 (\twolinesInseparable, which sets an "infinite" (10000) \widowpenalty).

Do these two parameters interact in a meaningful way for a 2-line paragraph?

(This is a theoretical question. I don't have a practical application right now other than the thought experiment of making sure that different macros that include a \widowpenalty or \clubpenalty don't conflict or create nonsensical or conflicting constraints.)

Best Answer

Let's look at what we get when we add \showoutput. I just show the diagnostic messages relative to the first pair of lines:

Completed box being shipped out [1]
\vbox(633.0+0.0)x407.0
.\glue 16.0
.\vbox(617.0+0.0)x345.0, shifted 62.0
..\vbox(12.0+0.0)x345.0, glue set 12.0fil
...\glue 0.0 plus 1.0fil
...\hbox(0.0+0.0)x345.0
..\glue 25.0
..\glue(\lineskip) 0.0
..\vbox(550.0+0.0)x345.0
...\write-{}
...\glue(\topskip) 10.0
...\rule(0.0+0.0)x*
...\penalty 10000
...\glue 384.0
...\glue 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 5.05556
...\hbox(6.94444+0.0)x345.0, glue set 306.11107fil
....\hbox(0.0+0.0)x15.0
....\OT1/cmr/m/n/10 l
....\OT1/cmr/m/n/10 i
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 e
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 1
....\penalty 10000
....\glue 0.0 plus 1.0fil
....\penalty -10000
....\glue(\rightskip) 0.0
....\glue(\rightskip) 0.0
...\penalty 10000
...\penalty 300
...\glue(\baselineskip) 5.05556
...\hbox(6.94444+0.0)x345.0, glue set 321.11107fil
....\OT1/cmr/m/n/10 l
....\OT1/cmr/m/n/10 i
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 e
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 2
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 5.05556

It's quite clear what happens: the command \\* does \vadjust{\penalty10000} and this \vadjust item find its way after the line containing line 1. But also the normal penalty pertaining to the paragraphs are added. In this case, the sum of \clubpenalty and \widowpenalty is inserted, resulting in \penalty300. Any penalty in the outer vertical list is a feasible page break point, and TeX can and does choose it in the seventh two line pair.

What does this mean? Simply that \\* should not be used in a paragraph for inhibiting a page break. In general \\ should not be used for breaking a line, to tell the complete truth.