3

I am writing a simple code documentation on Overleaf, but whenever I set my \ttfamily as sourcecodepro, quotes inside lstlisting are forcefully converted to curly quotes, regardless of whatever I try to fix.

Here is my sample .TeX file:

\documentclass{article}

\usepackage{fontspec}
\usepackage{listings}
\usepackage{polyglossia}
%\usepackage{sourcecodepro}

\lstset{basicstyle=\ttfamily, numberstyle=\ttfamily}
\setdefaultlanguage{english}

\begin{document}
\begin{itemize}
\item ``Normal text with correct quotes''
\item "Normal text with incorrect quotes"
\item \texttt{"Typewrite text with quotes"}
\item \verb/"Verbatim text with quotes"/
\item
    \begin{lstlisting}
    "Code listing with quotes"
    \end{lstlisting}
\end{itemize}
\end{document}

This code will generate following output, which is just as I desired: An image showing correct quotes in \texttt

However, when I delete the comment on line 6 and enable sourcecodepro package, all the quotes in \texttt style are becoming a mess: An image showing incorrect quotes in \texttt

I have looked into this, this, and this, but no success so far.

Is this a problem of sourcecodepro package, or am I doing something wrong?

1 Answer 1

3

sourcecodepro loads all fonts including the typewriter font with Ligatures=TeX. This is imho quite a dubious decision. You can reload the mono-font without this feature:

\documentclass{article}

\usepackage{fontspec}
\usepackage{listings}
\usepackage{polyglossia}
\usepackage{sourcecodepro}
\makeatletter
\defaultfontfeatures[\ttfamily]
       {
        Numbers   = \sourcecodepro@figurestyle ,
        Scale     = \SourceCodePro@scale ,
        Extension = .otf }

    % Monospace font
        \setmonofont
            [ UprightFont    = *-\sourcecodepro@regstyle ,
              ItalicFont     = *-\sourcecodepro@regstyle It ,
              BoldFont       = *-\sourcecodepro@boldstyle ,
              BoldItalicFont = *-\sourcecodepro@boldstyle It ]
            {SourceCodePro}
\makeatother

\lstset{basicstyle=\ttfamily, numberstyle=\ttfamily}
\setdefaultlanguage{english}

\begin{document}
\begin{itemize}
\item ``Normal text with correct quotes''
\item "Normal text with incorrect quotes"
\item \texttt{"Typewrite text with quotes"}
\item \verb/"Verbatim text with quotes"/
\item
    \begin{lstlisting}
    "Code listing with quotes"
    \end{lstlisting}
\end{itemize}
\end{document}

enter image description here

1
  • Thank you for the solution. Maybe I better contact the maintainer of sourcecodepro package for adding such option for disabling forceful ligature application. Feb 21, 2017 at 14:16

You must log in to answer this question.

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