5

I'm using minted for pretty printing console output and have just noticed that double hyphens, i.e. --, for program options are getting turned in en-hyphens, i.e. . A MWE is:

\documentclass{memoir}

\usepackage{minted}

\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmonofont{Courier}

\begin{document}

\begin{minted}{bash}
0-1--2---3
\end{minted}

\end{document}

and I see:

lualatex output

rather than what I'd hope for, a number of individual hyphens.

While making the MWE, I've realised that it's probably to do with an interaction with the fontspec option Ligatures=TeX, but I can't find a reliable way to selectively disable the option—I can do it inside XeLaTeX, but not luaLaTeX. Is it best just to ensure the mono font is loaded without Ligatures=TeX?

4

Your conjecture is true:

\documentclass{memoir}

\usepackage{minted}

\usepackage{fontspec}

% disable the default 'Ligatures=TeX' option
\defaultfontfeatures{}
\setmonofont{Courier}

\begin{document}

\begin{minted}{bash}
0-1--2---3
\end{minted}

\end{document}

enter image description here

If you want to have ligatures in running text also for the monospaced font, but not in minted, use a new font family. A small hack is necessary for retrieving the correct font family name.

\documentclass{memoir}

\usepackage{minted}

\usepackage{fontspec}

\setmainfont{TeX Gyre Termes}
\setmonofont{Courier}[Ligatures=TeX]

\defaultfontfeatures{}
\newfontfamily\noligsmonofamily[NFSSFamily=noligsmonofamily]{Courier}

\setminted{fontfamily=noligsmonofamily}

\begin{document}

This---has---ligatures

\texttt{This---has---ligatures}

\begin{minted}{bash}
0-1--2---3
\end{minted}

\end{document}

enter image description here

  • Yes, I know it's true. I really wanted to be able to have Ligatures=TeX everywhere for compatibility. – Sam Mason Jun 17 '15 at 14:00
  • @SamMason Just issue \defaultfontfeatures{} before defining \setmonofont; the fonts already loaded will respect the \defaultfontfeatures options in force at definition time; the option Ligatures=TeX is implicit at startup, with the most recent version of fontspec. – egreg Jun 17 '15 at 14:03
  • I was hoping I could have the option on most of the time and just have it disabled selectively within minted blocks. Maybe I should just create a version of the mono font with TeX ligatures off and just have minted specifically use it? – Sam Mason Jun 17 '15 at 15:09
  • @SamMason That would indeed be the best choice. I'll add some code later. – egreg Jun 17 '15 at 15:23
  • @SamMason Solution on line – egreg Jun 17 '15 at 15:46

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.