Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading