[ACCEPTED]-How do you display straight quotes instead of curly quotes when using LaTeX's 'listings' package?-miktex
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
\lstset{upquote=true}
before 7 begin
ing the list environment, or use
\begin{lstlisting}[upquote=true]
...
\end{lstlisting}
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).
Use:
\lstloadlanguages{<dialects you need>}
in the header. And 2 then set the language using either of the 1 above conventions for choosing options.
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:
\begin{lstlisting}
...
print{\qq}The temperature is{\qq},Celsius,{\qq}degrees Celsius{\qq}
...
\end{lstlisting}
Note 2 the curly braces which supposedly take listings 1 back to LaTeX mode (see escapechars
option of the package.)
Have you considered using a monospaced (typewriter) font 1 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}
Here is a solution
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{lmodern}
% in the listings package configuration, try:
literate={"}{\textquotedbl}1,
0
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. :)
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)
\newcommand{\QQ}[1]{``#1''}
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.