LaTeX Ligatures – How to Prevent LaTeX from Creating En-Dash and Em-Dash?

ligaturespunctuation

All over the internet, there's this question on how to make LaTeX do the en-dash and em-dash.

I have the opposite problem. I have some text from which I am generating HTML and LaTeX outputs. The original text has nothing to do with LaTeX and therefore -- and --- are needed to be written as they are, as opposed to being converted to en and em dashes.

Putting it in \texttt should probably solve it, but this could happen in normal text and I'd like to know if there is any other solutions.

P.S. I am writing the LaTeX files with a software, so in fact for example a thing like \dash{} instead of every - is easier for me, if such a thing exists that is!

Best Answer

-- and --- are TeX ligatures (like fl or fi). Disabling ligatures is one of the features of package microtype. You may deactivate all ligatures of all fonts:

\documentclass{article}
\usepackage{microtype}
\DisableLigatures{}
\begin{document}
---
\end{document}

or only the ligatures of the rm-family:

\documentclass{article}
\usepackage{microtype}
\DisableLigatures{family=rm*}
\begin{document}
---
\end{document}

or only the ligatures -- and --- of all fonts:

\documentclass{article}
\usepackage{microtype}
\DisableLigatures[-]{}
\begin{document}
---
\end{document}

or of one family, e.g. the tt-family:

\documentclass{article}
\usepackage{microtype}
\DisableLigatures[-]{family=tt*}
\begin{document}
\textrm{---} but \texttt{---}
\end{document}

See the manual of package microtype for more information about disabling ligatures.