# Remove extra space from double quotes in lstlisting environment

I have a book in which I'm using lstlisting for pseudocode. In some cases, I have strings, such as here:

\begin{lstlisting}
foreach (name in NameCollection)
{
Print Hello, {name}!''
}
\end{lstlisting}


My problem is that no matter what I do, I end up with a lot of extra space inside the double quotes; they're angled correctly but take up as much space as two characters.

Two consecutive backticks  and two consecutive typewriter apostrophes '' are TeX ligatures to produce English quotation marks “ and ”, respectively. In code listing, you should use a single symbol ", which is the most common way of introducing a string of text. I also strongly recommend to use a mono spaced font for code listing (they are designed for this purpose!).

\documentclass{article}
\usepackage{listings}
\lstset{
basicstyle=\ttfamily
}
\begin{document}
\begin{lstlisting}
foreach (name in NameCollection)
{
Print "Hello, {name}!"
}
\end{lstlisting}
\end{document}


• Unfortunately I get the same results whether I use the two apostrophes or a quote mark. But it does look better with a monospace font. Nov 2 '18 at 1:59
• @William Is it possible that, when you typed ", your TeX editor automatically converted the single symbol into two separate apostrophes? In that case, I suggest using the backspace or Ctrl+Z to get the single " back. Nov 2 '18 at 4:31
• Huh, you're right - it did! Dec 12 '18 at 1:51