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

2

3 Answers 3

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.

4
  • How do I make \showbox show this implicit \discretionary{}{}{}?
    – pts
    Commented Sep 22, 2015 at 15:58
  • 1
    @pts I don't think you can. The comment (ligature --) tells you about it.
    – egreg
    Commented Sep 22, 2015 at 16:03
  • 1
    @pts You probably realized that the answer to your question 3 is no.
    – egreg
    Commented Sep 22, 2015 at 16:10
  • Thanks for this documentation on the automatic discretionary. I fixed my answer on how to get non-breakable dashes without hindering hyphenation to work around this (using the T1 encoding’s 0x7F character), and it works successfully for the internal document at work.
    – mirabilos
    Commented Sep 4, 2016 at 18:54
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}
2
  • Thank you for the insight. Unfortunately it doesn't answer any of my questions.
    – pts
    Commented Sep 22, 2015 at 9: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. Commented Sep 22, 2015 at 9: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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .