latexlistings

Latex "listings" doesn't show code inside single and double quotation


Here's a minimal example of my project, where I use this R code:


\documentclass[12pt,a4paper,openany,oneside]{book}
\usepackage{listings}
\usepackage{color}
 \lstset{
         language=R,
         basicstyle=\footnotesize\ttfamily,
         numbers=left,           
         numberstyle=\tiny,       
         numbersep=5pt,        
         tabsize=4,                 
         extendedchars=true,         
         breaklines=true,
         keywordstyle=\textbf,           
         stringstyle=\color{white}\ttfamily,
         showspaces=false,       
         showtabs=false,           
         xleftmargin=17pt,
         framexleftmargin=17pt,
         framexrightmargin=5pt,
         framexbottommargin=4pt,
         showstringspaces=false
 }

\begin{document}
\begin{lstlisting}
"Try words inside double quotes"
'Try words inside single quotes'
airportsData <- read.csv("dataset\airports.txt", header = FALSE, sep = ",", quote = "\"")
colnames(airportsData) <- c("openflightCode" , "name", "city", "country", "IATA", "ICAO", "latitude", "longitude", "altitude", "timezone", "DST", "tzdb", "type", "source")
\end{lstlisting}
\end{document}

And when I compile the result is:

minimal example

As you can see, it doesn't show the code between quotes.


Solution

  • You set the colour for strings to white. Choose any other colour if you use it on a white paper...

    \documentclass[12pt,a4paper,openany,oneside]{book}
    \usepackage{listings}
    \usepackage{color}
     \lstset{
             language=R,
             basicstyle=\footnotesize\ttfamily,
             numbers=left,           
             numberstyle=\tiny,       
             numbersep=5pt,        
             tabsize=4,                 
             extendedchars=true,         
             breaklines=true,
             keywordstyle=\textbf,           
             stringstyle=\color{red}\ttfamily,
             showspaces=false,       
             showtabs=false,           
             xleftmargin=17pt,
             framexleftmargin=17pt,
             framexrightmargin=5pt,
             framexbottommargin=4pt,
             showstringspaces=false
     }
    
    \begin{document}
    \begin{lstlisting}
    "Try words inside double quotes"
    'Try words inside single quotes'
    airportsData <- read.csv("dataset\airports.txt", header = FALSE, sep = ",", quote = "\"")
    colnames(airportsData) <- c("openflightCode" , "name", "city", "country", "IATA", "ICAO", "latitude", "longitude", "altitude", "timezone", "DST", "tzdb", "type", "source")
    \end{lstlisting}
    \end{document}
    

    enter image description here