# How to have straight single quotes in lstlistings

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:

• Please provide a bit more information about your document and TeX system setup. E.g., do you use pdfLaTeX, XeLaTeX, or LuaLaTeX to compile your document? To help narrow down the list of things to consider, please provide a full MWE (minimum working example, starting with \documentclass{...} and ending with \end{document}) that produces the problem behavior you're looking to fix. – Mico Nov 17 '13 at 5:38
• @Mico, thanks, added minimal code. I hope this is sufficient. – perreal Nov 17 '13 at 5:50

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}

• You could simply load the package upquote... – karlkoeller Nov 17 '13 at 7:54
• inside the beamer document class, one must add the [fragile] option, i.e. \begin{frame}[fragile] (as far as I can tell, it fails without it) – PatrickT May 4 '17 at 9:53
• @PatrickT Yes, that's what the example code shows. Since it was already in the code posted in the question I didn't mention it explicitly. But beamer requires any verbatim text to be in a [fragile] frame. – Alan Munn May 4 '17 at 12:40
• @AlanMunn, True. In my code, [fragile] was the missing part that caused an error, so I thought I'd point it out explicitly. – PatrickT May 6 '17 at 6:37
• The sourcecodepro font doesn't include  so you might need to change font too. I'm currently using inconsolata to get around this problem. – Jeremy Smyth Jun 3 '19 at 9:38

Try using  (the symbol before the the numerical key of 1 above the alphabetical keys, it is on the key that shows: ~, when used with shift!). It works for me while creating documents.

So, essentially it will look like this:

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

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

-Sameer

• Hi and welcome to TeX.sx. You may want to check out our starter guide: Welcome to TeX.SX! This answer unfortunately doesn't actually answer the question. You've shown (correctly) how to get the correct curly quotes, but the question is asking how to get two identical straight quotes. – Alan Munn Nov 17 '13 at 6:16
• @AlanMunn: Thanks. Will take care next time. This was my first attempt to answer! – user33989 Nov 17 '13 at 6:26