4

I am using the listings-Package to display code. As I am using The Consolas Font as the Monotype-Default I expected straight quotes which isn't the case (check my MWE)

 \documentclass[a4paper]{article}
 \usepackage{listings}
 \usepackage{polyglossia}
 \setdefaultlanguage[]{english}

 \setmonofont[Ligatures=TeX]{Consolas}

  \lstset{frame=single}

  \begin{document}
  \begin{lstlisting}
  "some code to try"
  \end{lstlisting}

  \end{document}

Can Anyone help How to get straight quotes? enter image description here

3
  • listings doesn't use the monospaced font by default, add basicstyle=\ttfamily to \lstset. Commented Nov 11, 2013 at 14:12
  • That does not work @TorbjørnT. Is it because I use XeLaTex?
    – Kathiieee
    Commented Nov 11, 2013 at 14:15
  • After testing I see that it still does not produce straight quotes, but it should at least be using Consolas after adding that. Given that Consolas should give straight quotes, I don't know why the quotes appear as they do, I'm afraid. Commented Nov 11, 2013 at 14:19

1 Answer 1

3

This is actually caused by Ligatures=TeX, which causes fontspec to automatically convert a " to curly quotes, it appears. Further, as I mentioned in a comment, listings does not use the monotype font by default, so to actually use Consolas in the listings, add basicstyle=\ttfamily to lstset.

\documentclass[a4paper]{article}
\usepackage{listings}
\usepackage{polyglossia}
\setdefaultlanguage[]{english}

\setmonofont{Consolas}

\lstset{frame=single,basicstyle=\ttfamily}

\begin{document}
\begin{lstlisting}
"some code to try"
\end{lstlisting}
\end{document}

enter image description here

2
  • This works perfectly thanks! @Torbjørn T. Another question: What is the difference between \defaultfontfeatures{Mapping=tex-text} and the Ligatures=TeX?
    – Kathiieee
    Commented Nov 11, 2013 at 14:49
  • @Kathiieee Nothing, see the fontspec manual. I quote: 'Mapping enables a XeTeX text-mapping scheme, shown in Example 43. Using the tex-text mapping is also equivalent to writing Ligatures=TeX.' Commented Nov 11, 2013 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .