[Tex/LaTex] How to have straight single quotes in lstlistings

listingspunctuation

All single quotes in code samples are displayed as backticks and the copy-pasted code can't be compiled without fixing the quotation. Is it possible to prevent this?

for example:

\documentclass{beamer}
\usepackage{listings}
\begin{document}

\lstset{language=Python}
\begin{frame}[fragile]{Code}
\begin{lstlisting}
print 'hi' 
\end{lstlisting}
\end{frame}
\end{document}

Compiled with latexmk -pdf file.tex, which creates a log starting like: This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013).

Output:

enter image description here

Best Answer

You need to load the textcomp package and add upquote=true to your \lstset command. See ยง4.7 of the listings documentation. Alternatively, you can simply load the upquote package, which will make all verbatim quotes single quotes.

\documentclass{beamer}
\usepackage{listings}
\usepackage{textcomp}
\begin{document}

\lstset{language=Python,upquote=true}
\begin{frame}[fragile]{Code}
\begin{lstlisting}
print 'hi' 
\end{lstlisting}
\end{frame}
\end{document}

output of code