9

I have the following \hbox, and if I unbox it and put it to a paragraph (or when I just type aaa --, bbb or aaa --\nobreak, bbb), TeX is breaking the line between -- and ,.

> \box0=
\hbox(6.88875+1.94443)x46.1109
.\T1/lmr/m/n/10 a
.\T1/lmr/m/n/10 a
.\T1/lmr/m/n/10 a
.\glue 3.33333 plus 1.66666 minus 1.11111
.\T1/lmr/m/n/10 ^^U (ligature --)
.\T1/lmr/m/n/10 ,
.\glue 3.33333 plus 1.66666 minus 1.11111
.\T1/lmr/m/n/10 b
.\T1/lmr/m/n/10 b
.\T1/lmr/m/n/10 b

My questions:

  1. Why does such a line break happen?

  2. Why doesn't \nobreak disable the line break?

  3. Is it possible to fix it so that no line break happens when the source file contains --, (without any wrappers like \hbox or \mbox)?

pts
  • 1,103

3 Answers3

12

TeX adds an implicit \discretionary{}{}{} item after the \hyphenchar in the current font or any ligature that ends with that character (TeXbook, p. 95, last dangerous paragraph); the default value of \hyphenchar is 45, which in ASCII is exactly the hyphen.

Saying \nobreak after - does nothing, because at the top of page 95 there's the list of places where a line break is possible and discretionary items are included; so a break at the implicit discretionary break is possible and the penalty issued by \nobreak is discarded.

If you don't want to have a discretionary break after an en-dash, you can use \textendash that directly calls the character by number, so no ligature is involved.

egreg
  • 1,121,712
6

You can hide the ligature in a box. (It would have been helpful to have supplied an example)

\documentclass{article}
\setlength\textwidth{2cm}

\begin{document}

aa--bb aa--bb aa--bb aa--bb aa--bb aa--bb aa--bb 


aa\mbox{--}bb aa\mbox{--}bb aa\mbox{--}bb aa\mbox{--}bb aa\mbox{--}bb aa\mbox{--}bb aa\mbox{--}bb 

\end{document}
David Carlisle
  • 757,742
  • Thank you for the insight. Unfortunately it doesn't answer any of my questions. – pts Sep 22 '15 at 09:23
  • 3
    @pts not sure the first two are answerable, it happens because tex is programmed to add a break point after ligatures ending with hyphenchar, \nobreak doesn't work as it's not in the right place, it is after the break just as if you go \linebreak\mbox{}\nobreak the break can happen at the first penalty. If it were breaking at a space you could put \nobreak before the space but that doesn't work here. – David Carlisle Sep 22 '15 at 09:33
6

Egreg has already explained why you get the break. Beside \textendash you could also use \nobreakdash (from amsmath) to avoid it:

\documentclass{article}
\usepackage{amsmath}

\setlength\textwidth{2cm}
\begin{document}

aa --, aa --, aa --, aa --, aa --, aa --, aa --,

\bigskip

aa --, aa \textendash, aa --, aa --, aa --, aa --, aa --,

\bigskip

aa --, aa \nobreakdash--, aa --, aa --, aa --, aa --, aa --,

\end{document}

enter image description here

Ulrike Fischer
  • 327,261