My problem is that when I use the correct quotation marks ``'', lstset does not recognize strings in my code and thus does not color-code them. When I use standard double quotes "", the leading quotes are backwards. Thoughts?
\documentclass[12pt, letterpaper]{article}
\usepackage [english]{babel}
\usepackage [autostyle, english = american]{csquotes}
\MakeOuterQuote{"}
\usepackage{listings}
\newcommand{\dbllq}{``}
\newcommand{\dblrq}{''}
\lstset{
literate={``}{\dbllq}1 {''}{\dblrq}1 % so that double quotes appear correctly in the code
}
\usepackage{color}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\lstset{ %
basicstyle=\normalsize, % the size of the fonts that are used for the code
commentstyle=\color{mygreen}, % comment style
keywordstyle=\color{blue}, % keyword style
language=C, % the language of the code
stringstyle=\color{mymauve}, % string literal style
showspaces=false,
}
\begin{document}
"Quotes in the document work properly."
\begin{lstlisting}
displayTextLine(1, "Right color, wrong quotes"); // comments are green
for(1, ``Right quotes, wrong color''); // nonsensical code but keywords are blue
\end{lstlisting}
\end{document}
morestringdidn't work. Did it compile? If not, you may have an older version oflistings. Otherwise, I should have noted that you have to remove yourliterateoption, since this redefines the delimiters that we are choosing with themorestringoption. – alaferg Apr 14 '15 at 20:57literateoption. When I usedmorestring, the quotes faced the right way and the text was the correct color, but the double quotation marks were oddly spaced as if they were two separate characters instead of one. It was a bit weird-looking. Not sure why that happened. – Margaux Apr 15 '15 at 16:42