Basically I want
\mint{python}|'banana'|
to produce straight single quotes, rather than the curly ones it normally produces (in pdflatex).
Basically I want
\mint{python}|'banana'|
to produce straight single quotes, rather than the curly ones it normally produces (in pdflatex).
You can use the package upquote. Note the package loads the package textcomp
The package upquote works also with listings.
% !TEX program = pdflatex --shell-escape
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{minted}
\usepackage{upquote}
\begin{document}
\mint[fontfamily=tt]{python}|'banana'|
\end{document}
The result:

If you are using pygmentize version 1.6 that the package upquote can't do its job. To fix this issue you can use the following hack:
\listfiles
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{minted}
\usepackage{upquote}
\AtBeginDocument{%
\def\PYZsq{\textquotesingle}%
}
\begin{document}
\mint[fontfamily=tt]{python}|'banana'|
\end{document}
Note if you are working with XeLaTeX or LuaLaTeX the hack isn't needed.
upquote package modifies all verbatim text (\verb and the verbatim environment) to render ' and \`` as the upright versions, not the “smart”‘and’`. Since (as I understand it) minted and listings rely on fancyvrb, which itself calls out to verbatim text under the hood, this has the desired effect.
– Antal Spector-Zabusky
Sep 27 '12 at 06:02
xelatex or lualatex it works. It seems this is a bug of pygmentize version 1.6. With version 1.2 it works.
– Marco Daniel
May 31 '13 at 10:05
mathspec package, either.
– brannerchinese
Nov 08 '13 at 04:47
mathspace includes that you are compiling with XeLaTeX. In this case the package or the "hack" isn't necessary.
– Marco Daniel
Nov 08 '13 at 08:27
lstlisting when used with \upquote.
– brannerchinese
Nov 09 '13 at 15:43