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?

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

  • Thank you for the solution. Maybe I better contact the maintainer of sourcecodepro package for adding such option for disabling forceful ligature application. – Ardie Hyun Hwang Feb 21 '17 at 14:16

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.