# Locally disabling en and em dash ligatures

A programming tool that I use (coqdoc) generates LaTeX documentation from my source code. Parts of the manual include pretty-printed code listings and math proofs.

These listings and proofs are rather math-heavy, and thus are not wrapped in verbatim or lstlistings. When successions of dashes are found (-- or ---) in code or proofs, they are dumped literally in the LaTeX output, and thus get converted to – and — as the document is typeset by pdflatex. Code and proof listings are wrapped in a particular environment, which I can renew.

What can I add to my preamble to disable en and em dash ligatures in that specific environment?

Ideally, I would like something like the following:

\documentclass{article}
\usepackage[T1]{fontenc}
\renewenvironment{coqdoccode}{MAGIC HERE}{}

\begin{document}
This should be an an and an em dash: -- ---
\begin{coqdoccode}
This should be two and three small dashes: -- ---
This should still be ligatures: ff fi
\end{coqdoccode}
\end{document}


microtype only seems to be able to disable ligatures at the entire document level.

• Is LuaLaTeX an option? Switching off ligatures in LuaLaTeX Apr 7 '15 at 17:54
• Unfortunately no; the output of the tool is heavily reliant on pdflatex. Apr 7 '15 at 17:55
• The verbatim environment use \@noligs to stop -- ligatures, and the tt font has no ff ligatures, is monospace acceptable for this use? Apr 7 '15 at 17:57

Activate the hyphen in the coqdoccode environment, defining it as a hyphen followed by a zero kern.

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

\newcommand{\activatehyphen}{%
\begingroup\lccode~=-
\lowercase{\endgroup\def~}{\char\-\kern0pt }%
\catcode\-=\active
}

\newenvironment{coqdoccode}
{\flushleft\activatehyphen\ttfamily}
{\endflushleft}

\begin{document}
This should be an an and an em dash: -- ---
\begin{coqdoccode}
This should be two and three small dashes: -- --- \\
This should still be ligatures: ff fi \\
\end{coqdoccode}
\end{document}


I added \ttfamily just for clarity, but it's not necessary.

This is the result without \ttfamily in the definition

• I don't see ligatures for ff and fi in the last output... Apr 7 '15 at 21:11
• @Bakuriu That's because I used \ttfamily. Apr 7 '15 at 21:13
• That's awesome, thanks. Could you explain how this works? I understand that it makes - active, but I'm not sure what the \lowercase and \lccode parts do. Apr 7 '15 at 21:44
• Apr 7 '15 at 22:02