Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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)

like image 836
Paul Vincent Craven Avatar asked Jan 11 '09 04:01

Paul Vincent Craven


People also ask

How do you insert a straight quote?

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.

How do you quote a quote in LaTeX?

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.)

What is the difference between a curly quote and a straight quote?

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.


1 Answers

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 begining 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.

like image 114
dmckee --- ex-moderator kitten Avatar answered Oct 14 '22 19:10

dmckee --- ex-moderator kitten