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):
(Direct link to image of incorrect output)
Straight quotes are the two generic vertical quotation marks located near the return key: the straight single quote ( ' ) and the straight double quote ( " ). Curly quotes are the quotation marks used in good typography.
Single quotation marks are produced in LaTeX using ` and ' . Double quotation marks are produced by typing `` and '' . (The `undirected double quote character " produces double right quotation marks: it should never be used where left quotation marks are required.)
Curly quotes are often referred to as smart quotes. That's because they curve toward the text you're quoting. This is done automatically in most word processors. Straight quotes are what they sound like — straight, vertical marks without any indication of which word or phrase it's surrounding.
I see in the documentation (which should have been distributed with the packge, but is available at http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf) for listings
that there is a settable property called upquote
to take care of this.
From the documentation:
upquote=⟨true|false⟩ false determines whether the left and right quote are printed ‘’ or `'. This key requires the textcomp package if true.
Do something like
\lstset{upquote=true}
before begin
ing the list environment, or use
\begin{lstlisting}[upquote=true] ... \end{lstlisting}
It is also possible that tis property is already set for you in the appropriate language definition (see the docs again, big list of predefined languages on page 12).
Use:
\lstloadlanguages{<dialects you need>}
in the header. And then set the language using either of the above conventions for choosing options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With