[texhax] How to avoid page breaks between paragraphs and lists?

Ian Collier imc at comlab.ox.ac.uk
Tue Nov 4 14:53:13 CET 2003


I wrote:
>| {\makeatletter\gdef\reallynopagebreak{\par\nopagebreak\@nobreaktrue}}

Stefan.Wachter at gmx.de responded:
>PS: Can you explain what the macro does?

While inspecting the LaTeX source to find out where the page break
comes in, I noticed that the list environments tend to insert a
\penalty before each \item (which basically means "allow a page
break" even if you have just said \nopagebreak); however, I also
noticed that LaTeX has an \if at nobreak setting (usually used at the
beginning of a section, I think) which tells it to omit the \penalty.

So the above macro uses this insider information to turn off the
\penalty at the beginning of the list, which means that the \nopagebreak
command can take effect.  The \makeatletter command is required in order
to use commands with "@" in them (as they are internal commands which
shouldn't be used casually).
-- 
---- Ian Collier : imc at comlab.ox.ac.uk : WWW page below
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml


More information about the texhax mailing list