[texhax] Orphan section heads

Uwe Lück uwe.lueck at web.de
Fri Oct 21 00:01:15 CEST 2005

I bet I've got it, at least concerning Philip Taylor's sketch
of an example. I see two bugs in LaTeX that might be
responsible or raise the danger of orphan headings.

At 16:12 21.09.05, Philip TAYLOR wrote:
>Hmmm, sadly I can now demonstrate that it
>is only too easy to get an orphaned subsection
>head : this accomplishes it for me, though
>I very much wish that it didn't :-(((
>         \documentclass [final]{ltugproc}
>         \usepackage {graphicx}
>         \hfuzz = 1\jot
>         \overfullrule = 1\jot
>         \hyphenation {legit-imately}
>         \flushbottom
>                 . . .
>         \subsection {byz-data.dat}
>         \begin{verbatim}
>                 . . .

1. LaTeX's \@verbatim contains

     \if at minipage\else\vskip\parskip\fi

not preceded by any \penalty, so it's possible to break there.
I bet this is responsible for Philip Taylor's example ...

At 16:49 21.09.05, William F. Adams wrote:
>On Sep 21, 2005, at 10:12 AM, Philip TAYLOR wrote:
>>         \subsection {byz-data.dat}
>>         \begin{verbatim}
>Isn't the space inserted by the verbatim environment what's causing this?

... oh, sometimes I understand other people's words only after
I have found the same thought by myself. However, it is encouraging
when two people come to the same conclusion independently. I only
wonder how the discussion went on, instead of focussing on the fact
that there is a LaTeX bug here. To fix it:

At 18:40 14.09.05, Robin Fairbairns wrote:
>on the contrary, the latex standard classes put tediously high
>penalties after section heads: this makes it difficult to write an
>outline document, since the penalties mean that it's impossible to
>break the page until there's some text in the sections.

... not quite so! or even more: LaTeX's sectioning macros use
\@afterheading, and the latter uses \@nobreaktrue instead of
penalties, because after the previous \vskip on the main
vertical list it is impossible to find out what \penalty precedes
that \vskip (because \unskip doesn't work here).*) So to prevent
a heading from sticking to the very bottom of the page, each
following \vskip before the next hmode must be preceded by
\if at nobreak \nobreak \fi .

I don't find this in the LaTeX Bug Database.

2. Recently I used \addvspace for some self-made sectioning
commands ... and got orphan heads. I found that this is due
to the \vskip's in (\addvspace and) \@xaddvskip -- which are not
preceded by \penalties. I made my own version of \addvspace
by preceding the \vskip's with \if at nobreak \nobreak \fi .
\addpenalty is dangerous for the same reason.

LaTeX's \@startsection is wise enough to use \addpenalty
and \addvspace under \if at nobreak ... \else only. Similarly
\@item, which does \@nbitem ("no-break-item") instead of
\addpenalty and \addvspace under \if at nobreak. \@nbitem
... contains \addvspace ... incredible ... this may break in
two senses of `to break' ...

I would just use \if at nobreak \nobreak \fi again and again
... so I would suggest something like

     \def\@ifnb at nb@vskip{\if at nobreak \nobreak \fi \vskip}

When I search the LaTeX Bug Database for \addvspace,
I don't get subject lines that hint at the former problem.
Maybe apart from the very first one, but opening that
report still does not show the previous observation.

Must I make proper bug reports? Mostly I have preferred
to write my own patch instead of making proper bug reports.
I collected the bugs on a slip of paper for each of them,
hoping that I sometimes could find the time to make a bug
report ... One of them (orphan headings with \nofiles and
\label) was fixed independently later.

(A certain address on the LaTeX Bug website is allowed
to be used for offering volunteering, but I take it that
"one-time volunteering" is not included.)

-- Uwe.
*) Oh! Not quite so: you can change the output routine and
call it here in order to \unskip in \box255 etc.! 

More information about the texhax mailing list