# How can I stop LaTeX from converting two hyphens to a single hyphen when loading package fontenc?

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

\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

-
@Herbert: An explanation would be nice. –  Hendrik Vogt Jan 27 '11 at 17:53
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. –  CommuSoft Jan 27 '11 at 18:06
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
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 –  CommuSoft Jan 27 '11 at 18:18
I must be a little slow... I still think fontenc must have something to do with it because I can get the double hyphen using \texttt{--} without the {} in between the hyphens if I don't load fontenc. But the conclusion I draw from what you have said (and I may be wrong; just trying to understand) is that I should always have to insert the {} between two hyphens, even if in the \texttt{} so that the hyphens don't collapse? And it's not that they hyphens are becoming either en- or em-dashes, it's that the second one hyphen seems to disappear. –  Mike Broschinsky Jan 27 '11 at 18:30