55

In the following minimal test document, I can have two hyphens appear as two hyphens (which is what I want):

\documentclass[letterpaper]{article}

\begin{document}
A hyphen: \texttt{-}

Two hyphens: \texttt{--}

Three hyphens: \texttt{---}

\end{document}

But in this second test document where I load the fontenc package, I get different behavior; the single hyphen is displayed; the double hyphen is collapsed to a single hyphen, and the triple hyphen is collapsed to a double hyphen:

\documentclass[letterpaper]{article}
\usepackage[T1]{fontenc}

\begin{document}
A hyphen: \texttt{-}

Two hyphens: \texttt{--}

Three hyphens: \texttt{---}
\end{document}

I read that loading fontenc is a Good Idea, so I want to do that; but I want my double hyphen too. Have I missed something terribly obvious?

System: MiKTeX 2.8 on Windows XP Pro.

  • Welcome to tex.sx! Note that you don't have to (and shouldn't) sign with your name since it automatically appears in the lower right corner of your post. – Hendrik Vogt Jan 27 '11 at 17:54
  • @Hendrik: Thanks for the tip! I'll be more careful in future. – Mike Broschinsky Jan 27 '11 at 18:07
60

-- is a so-called TeX-Ligature which is converted into the n-dash. -{}- breaks this combination.

\documentclass[letterpaper]{article}
\usepackage[T1]{fontenc}

\begin{document}
A hyphen: \texttt{-}

Two hyphens: \texttt{-{}-}

Three hyphens: \texttt{-{}-{}-}
\end{document}

or define own macros for this

  • 7
    @Herbert: An explanation would be nice. – Hendrik Vogt Jan 27 '11 at 17:53
  • 2
    It's quite easy. LaTeX sees two hyphens as a single token representing another sort of hyphen. By using a {} token. You say to LaTeX things before and after the {} chars have another context. TeX can only read multiple chars as one token if they are in the same context. The details can be read in "the TeXbook" and "TeX the program" of Donald E. Knuth. – Willem Van Onsem Jan 27 '11 at 18:06
  • 1
    I still don't understand why the difference between the first minimal example, which doesn't load fontenc and which does output multiple hyphens, and the second minimal which does load fontenc and collapses the hyphens. – Mike Broschinsky Jan 27 '11 at 18:10
  • 1
    Fontenc specifies the way how it has been read. But for consistent TeX, you should use the '{}' patterns. With '{}' you say to TeX "All right, forget everything about the past (except labels,...), and take a new look at this". When you type "--" TeX will see this as a pattern for a longer hyphen. With '{}' between it, it will have forgotten that there was already a hyphen. TeX knows four different types of hyphens: en.wikibooks.org/wiki/LaTeX/Formatting#Dashes_and_Hyphens – Willem Van Onsem Jan 27 '11 at 18:18
  • 1
    @Mike: \verb is used, when you exactly want the same as the argument in typewriter or any other defined font. \texttt is used, when you want the same characters as in the default text but only in typewriter. 2.8.3759 seems the version number of MiKTeX, but not of pdftex. However, that is anyway not a problem. – user2478 Jan 27 '11 at 19:23
9

This approach didn't work for me in the bibliography, if you have the same problem simply insert one of the phantom commands:

@article{Foo,
  title = {Hello -\phantom{}- World},
}

This will work as desired.

1

For me, -{}- is not working for breaking the ligature in --. The trick -\phantom{}- works, but it is a bit wordy. I found that the command for the italic correction could be the best choice in this particular case: this -\/- works for me in every case.

Please see difference between {} and / for breaking ligatures for further details.

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.