The \nobreak
command is not documented in the LaTeX manual nor in the "LaTeX Companion". Its meaning is just \penalty10000
which makes it useful both in horizontal and vertical mode, but this ubiquity makes it a bit dangerous.
The meaning of \nolinebreak
is "look if there's an optional argument and, if not, call the inner macro \@no@lnbk
with argument 4", which means doing
\ifvmode
\@nolnerr
\else
\@tempskipa\lastskip
\unskip
\penalty\@M
\ifdim\@tempskipa >\z@
\hskip\@tempskipa\ignorespaces
\fi
\fi
which checks whether we are in horizontal mode and does a bit of juggling: if
\nolinebreak
is preceded by a space (a normal interword space or an explicit \hspace
), it is removed, the penalty is issued and the space is reinserted.
A bad habit (of which I admit to be guilty) is to use the shorter command when it's sure that it will do the right thing. For instance,
$a=\nobreak b$
is faster than $a=\nolinebreak b$
because there's no check to be performed and no space to be shifted.
One can also find \nobreak
just after a \par
, meaning that a vertical space after \par\nobreak
will never be used for a page break.
Of course it's better to use \par\nopagebreak
in this case. But, alas, bad habits prevail. Use \nopagebreak
.
(I promise I'll be more LaTeX savvy in the future.)