Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

In plain TeX there is \nobreak, equivalent to \penalty 10000. In ConTeXt, it's the same (defined in the file spac-ver.mkiv).

share|improve this answer
    
This seems to have no effect, if placed after a macro. E.g. \macro{Some text}\nobreak A. How is this done after a macro? –  Village Apr 7 '12 at 8:40
1  
@Village: probably doesn't depend on there being a macro: with \def\macro#1{#1} you get the same as Some text\nobreak A. What macro are you testing with? –  Bruno Le Floch Apr 7 '12 at 9:07
2  
If you \macro ends with e.g. a skip, you might need to either redefine it, or say e.g. \def\reallynobreak{\unskip\penalty 10000} –  mbork Apr 7 '12 at 9:46
add comment

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).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.