The command \nolinebreak[4], if placed between two characters, should prevent a line break from appearing in that location. This command does not seem to be defined in ConTeXt. Is there an equivalent for this in ConTeXt, or for plain TeX which is also compatible with ConTeXt?
- 13,603
- 23
- 116
- 219
2 Answers
In plain TeX there is \nobreak, equivalent to \penalty 10000. In ConTeXt, it's the same (defined in the file spac-ver.mkiv).
- 13,385
The definition of \nolinebreak in LaTeX is, skipping over the details,
\ifvmode
\@nolnerr
\else
\@tempskipa\lastskip\unskip
\penalty\@M
\ifdim\@tempskipa>\z@
\hskip\@tempskipa
\fi
\fi
The first conditional simply issues an error if \nolinebreak is found in vertical mode. In horizontal mode it stores the last skip (if there isn't one the stored value is zero) and removes it (if present). Then a penalty of 10000 is issued and the skip is reinstated.
Just use a temporary skip register instead of \@tempskipa, for instance \skip8. If you need the full syntax \nolinebreak[<number>] then something more complicated has to be used.
\catcode`@=11
\def\nolinebreak{\futurelet\next\nolinebreak@a}
\def\nolinebreak@a{%
\ifx\next[\expandafter\nolinebreak@b\else\nolinebreak@b[4]\fi}
\def\nolinebreak@b[#1]{%
\ifvmode\else
\skip8=\lastskip\unskip
\penalty\ifcase#1 0 \or 2500 \or 5000 \or 7500 \or \@M\fi % change values at will
\ifdim\skip8>\z@\hskip\skip8 \fi
\ignorespaces
\fi}
\catcode`@=12
The trick is that glue isn't a feasible for line breaking if it follows a penalty. For example, Plain TeX defines ~ as
\def~{\penalty\@M \ }
(where \@M stands for 10000).
- 1,121,712
\macro{Some text}\nobreak A. How is this done after a macro? – Village Apr 07 '12 at 08:40\def\macro#1{#1}you get the same asSome text\nobreak A. What macro are you testing with? – Bruno Le Floch Apr 07 '12 at 09:07\macroends with e.g. a skip, you might need to either redefine it, or say e.g.\def\reallynobreak{\unskip\penalty 10000}– mbork Apr 07 '12 at 09:46