6

It looks like -- and \textendash have different line-breaking behaviour in LaTeX. I'd assumed that they would just insert an en dash character, and then act the same, but it looks like they don't from this example:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

I'm going to write a really, really, really long numerical range: 10000000\textendash 20000000 which should overflow the justification box, which you can see from my continued typing below the above line.

I'm going to write a really, really, really long numerical range: 10000000--20000000 which should overflow the justification box, which you can see from my continued typing below the above line.

% This paragraph uses an en dash character directly
I'm going to write a really, really, really long numerical range: 10000000–20000000 which should overflow the justification box, which you can see from my continued typing below the above line.

\end{document}

example output

Why is this the case, and are there any other differences I should be looking out for?

Note that inserting an en dash directly (the last paragraph) also seems to act like \textendash, which makes me wonder if -- is truly an en dash?

3
  • 5
    -- are two hyphens, which are later on converted as a ligature into the en-dash glyph used by \textendash. In pdflatex this happens after it has decided that hyphenation is allowed after a hyphen. In lualatex the behaviour is different. – Ulrike Fischer Jun 17 at 9:49
  • @UlrikeFischer aha! That's good to know — if you post as an answer, I'd be happy to accept. – Alec Jun 17 at 9:50
  • Another difference is that -- is easier to type, easier to read for humans but also exportable asis with the traditional copy & paste method to LibreOffice and rmarkdown, (relevant if collaborators are not LaTeX fans, for instance). – Fran Jul 9 at 7:40
6

With --, there is a feasible break points, because the ligature ends with the default hyphen character. (Pedantic note: this happens only if the \hyphenchar parameter for the current font is the hyphen.)

On the other hand, \textendash is essentially equivalent to \char21 and since this has nothing to do with the hyphen character, no break point is present after it. The same happens if you type U+2013, because in pdflatex this is converted to \textendash.

13
  • So, -- is the advised thing to type? – Gaussler Jun 17 at 14:42
  • @Gaussler It depends on whether you want to allow a line break past it. – egreg Jun 17 at 14:50
  • In these kinds of cases, one usually wants to make a global, consistent choice. Either it is always allowed at “–”, or it’s not. And I think the literal tradition says that they should be allowed, doesn’t it? – Gaussler Jun 17 at 14:52
  • @Gaussler That really depends on different typographic traditions and personal preferences. – egreg Jun 17 at 15:02
  • 2
    @Gaussler He offers riddles to keep us in suspense. Time to get out the secret decoder ring...hmmm..30 = 2x2x2x2x2-2. Wait!...wait!...decode coming through now: B-E---S-U-R-E---T-O----D-R-I-N-K---Y-O-U-R---O-V-A-L-T-I-N-E ?? (ref: cbr.com/…) – Steven B. Segletes Jul 8 at 20:22
0

I would add that I ran this file through all three TeX engines. pdfTeX, as expected, gives the results described. XeTeX, correctly breaks at the – in all three paragraphs. LuaTeX, surprisingly, does not break at any of the en dashes. This last seems to be very bad behavior. I'm sticking with my recommendation for people who want to use Unicode input to prefer XeLaTeX over the other engines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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