2

Consider the following MWE:

% Compile with pdfLaTeX
\documentclass{article}
\usepackage{FiraMono}
\usepackage{listings}
\lstset{
  language=[LaTeX]TeX,
  basicstyle=\ttfamily,
  columns=fullflexible,
  keepspaces=true
}
\begin{document}
\begin{lstlisting}
\ifx\foo\baz
\fi
\end{lstlisting}
\end{document}

listing

Why is the backslash rendered as double-quote? And how to disable the fi ligature? Note that these two problems disappear if one compiles the above MWE with XeLaTeX.


Reasons for columns=fullflexible: The default columns=fixed puts each character in a box of fixed width 0.6em. Coincidentally, 0.6em happens to be the width of a character from Fira Mono. But for other typefaces, the widths differ. The option columns=fullflexible sets each character to its natural width, which is desired.

6

You can use the microtype package to disable ligatures for all tt fonts. This will also disable kerning for that particular font, but that's usually unwanted for typewriter text anyway.

For the backslash, the default OT1 encoding does not have enough slots, so it is not mapped. Using T1 encoding fixes the problem.

% Compile with pdfLaTeX
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{FiraMono}
\usepackage{listings}
\lstset{
  language=[LaTeX]TeX,
  basicstyle=\ttfamily,
  columns=fullflexible,
  keepspaces=true
}
\DisableLigatures{encoding = *, family = tt* }
\begin{document}
\begin{lstlisting}
\ifx\foo\baz
\fi
\end{lstlisting}
\end{document}

enter image description here

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.