I am using pdfLaTex. I'm trying to define a command \cmd that prints its argument in a typewriter font (i.e. using \texttt for code formatting). For example, I want
\cmd{--my-command} to print exactly
--my-command (with two separate hyphens), but instead it produces an en‐dash followed by my-command (i.e. “–my-command”).
My original macro:
\newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} I’ve tried several methods to “break” the ligature, including:
- Disabling hyphen ligatures:
\usepackage{microtype} \DisableLigatures[-]{encoding = *, family = * } \newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} - Disabling all ligatures:
\usepackage{microtype} \DisableLigatures[]{encoding = *, family = * } \newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} - Manually inserting a zero-width kern between hyphens (using xstring):
\usepackage{xstring} \newcommand{\cmd}[1]{% \StrSubstitute{#1}{--}{-\kern0pt-}[\temp]% \texttt{\temp}% } - Disabling all ligatures:
\usepackage{microtype} \DisableLigatures{} \newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} - Disabling all ligatures:
\usepackage{microtype} \DisableLigatures{family=rm*} \newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} None of these methods work as expected; the output still ligatures the two hyphens.

\verb|...|(or listings or minted)\documentclass{article}\begin{document}\texttt{\detokenize{--my-command}}\end{document}shows no ligatures. There's something else going on which you do not show.