Search code examples
latexmiktex

How do you display straight quotes instead of curly quotes when using LaTeX's 'listings' package?


I'm using LaTeX's "listings" package to format source code. Unfortunately I get curly quotes instead of straight quotes. Since the curly quotes don't always point in the right direction, it looks bad. How can I get straight quotes instead?

I'd prefer not to change or filter the source code itself. Filtering the code to properly change " to `` or '' would work, but this is easier done than said with multiple quotes on a line, or quotes spanning multiple lines. Or you could use symbol or a host of other things. But I'd really like to keep the source unchanged.

Example LaTeX:

\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
Fahrenheit=input("What is the Fahrenheit temperature?")
Celsius=(5.0/9.0)*(Fahrenheit-32)
print"The temperature is",Celsius,"degrees Celsius"
\end{lstlisting}
\end{document}

Example output (using Miktex on windows): Image of source code

(Direct link to image of incorrect output)


Solution

  • Have you considered using a monospaced (typewriter) font for the listing? The following example works:

    \documentclass{article}
    \usepackage{listings}
    \lstset{basicstyle=\ttfamily} % <<< This line added
    \begin{document}
    \begin{lstlisting}
    Fahrenheit=input("What is the Fahrenheit temperature?")
    Celsius=(5.0/9.0)*(Fahrenheit-32)
    print"The temperature is",Celsius,"degrees Celsius"
    \end{lstlisting}
    \end{document}