How can I get straight double quotes in listings?
Simply add \usepackage[T1]{fontenc}
to your preamble. Note that you don't need the upquote
package if you load textcomp
and set listings
' upquote
key to true
.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{listings}
\lstset{upquote=true}
\begin{document}
\begin{lstlisting}
echo "Hello, world!"
\end{lstlisting}
\end{document}
For, me the above solutions did not work.
The main problem can be seen in listings.sty
, lines 922-943, where a dispatch table of handling special characters in created, but the upquote is only done for single quotes.
One can fix this by adding the following to your preamble:
\usepackage{listings}
\lstset{upquote=true}
% ...
\makeatletter
\lst@CCPutMacro
\lst@ProcessOther {"22}{\lst@ifupquote \textquotedbl
\else \char34\relax \fi}
\@empty\z@\@empty
\makeatother
% ...
which monkey-patches that table.
Caveat emptor: this is a terrible hack which relies on modifying internal macros of the listings package. This may arbitrarily and completely break and may even not work on your TeX distro.