[ACCEPTED]-How do you display straight quotes instead of curly quotes when using LaTeX's 'listings' package?-miktex

Accepted answer
Score: 25

I see in the documentation (which should 11 have been distributed with the packge, but 10 is available at http://www.ctan.org/tex-archive/macros/latex/contrib/listings/listings.pdf) for listings that there is a settable 9 property called upquote to take care of this.

From 8 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


before 7 begining the list environment, or use


It is also 6 possible that tis property is already set 5 for you in the appropriate language definition 4 (see the docs again, big list of predefined 3 languages on page 12).


\lstloadlanguages{<dialects you need>}

in the header. And 2 then set the language using either of the 1 above conventions for choosing options.

Score: 10

dmckee's answer above probably works. If you drop your 9 last condition, i.e. you permit changes 8 to the code, then there is a more generic 7 solution, which I tend to use whenever (La)TeX 6 renders a character somehow differently 5 than I expect it to do is to use the \symbol command. I 4 list it here because it can be useful in 3 other situations as well:

\newcommand{\qq}{\symbol{34}} % 34 is the decimal ascii code for "

And then your example:

print{\qq}The temperature is{\qq},Celsius,{\qq}degrees Celsius{\qq}

Note 2 the curly braces which supposedly take listings 1 back to LaTeX mode (see escapechars option of the package.)

Score: 10

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

\lstset{basicstyle=\ttfamily} % <<< This line added
Fahrenheit=input("What is the Fahrenheit temperature?")
print"The temperature is",Celsius,"degrees Celsius"
Score: 8

Here is a solution


% in the listings package configuration, try:  


Score: 6

I had the same problem, using fontspec, and 4 the solution was to not set \defaultfontfeatures{Mapping=tex-text}, but instead setting 3 Mapping=tex-text specifically on only the main and sans 2 font, and leaving the tt font to it's own 1 devices. :)

Score: 1

Maybe it's because I installed listings 6 early as a LaTeX user, but I'm surprised 5 to learn that without the listings package 4 the behaviour is any different.

My solution 3 was similar to David Hanak's, but I used 2 the symbols for double-quote as described 1 in the LaTeX Cheat Sheet (http://stdout.org/~winston/latex)


More Related questions