“Latex ‘listings’ 不显示单引号和双引号内的代码。”

huangapple go评论54阅读模式
英文:

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

问题

这是我的项目的一个简单示例,在这里我使用了这段R代码:

\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}
"尝试双引号内的文字"
'尝试单引号内的文字'
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}

当我编译结果时:

“Latex ‘listings’ 不显示单引号和双引号内的代码。”

正如您所见,它不显示引号内的代码。

英文:

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}
&quot;Try words inside double quotes&quot;
&#39;Try words inside single quotes&#39;
airportsData &lt;- read.csv(&quot;dataset\airports.txt&quot;, header = FALSE, sep = &quot;,&quot;, quote = &quot;\&quot;&quot;)
colnames(airportsData) &lt;- c(&quot;openflightCode&quot; , &quot;name&quot;, &quot;city&quot;, &quot;country&quot;, &quot;IATA&quot;, &quot;ICAO&quot;, &quot;latitude&quot;, &quot;longitude&quot;, &quot;altitude&quot;, &quot;timezone&quot;, &quot;DST&quot;, &quot;tzdb&quot;, &quot;type&quot;, &quot;source&quot;)
\end{lstlisting}
\end{document}

And when I compile the result is:

“Latex ‘listings’ 不显示单引号和双引号内的代码。”

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

答案1

得分: 0

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}
&quot;Try words inside double quotes&quot;
&#39;Try words inside single quotes&#39;
airportsData &lt;- read.csv(&quot;dataset\airports.txt&quot;, header = FALSE, sep = &quot;,&quot;, quote = &quot;\&quot;&quot;)
colnames(airportsData) &lt;- c(&quot;openflightCode&quot; , &quot;name&quot;, &quot;city&quot;, &quot;country&quot;, &quot;IATA&quot;, &quot;ICAO&quot;, &quot;latitude&quot;, &quot;longitude&quot;, &quot;altitude&quot;, &quot;timezone&quot;, &quot;DST&quot;, &quot;tzdb&quot;, &quot;type&quot;, &quot;source&quot;)
\end{lstlisting}
\end{document}
英文:

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}
&quot;Try words inside double quotes&quot;
&#39;Try words inside single quotes&#39;
airportsData &lt;- read.csv(&quot;dataset\airports.txt&quot;, header = FALSE, sep = &quot;,&quot;, quote = &quot;\&quot;&quot;)
colnames(airportsData) &lt;- c(&quot;openflightCode&quot; , &quot;name&quot;, &quot;city&quot;, &quot;country&quot;, &quot;IATA&quot;, &quot;ICAO&quot;, &quot;latitude&quot;, &quot;longitude&quot;, &quot;altitude&quot;, &quot;timezone&quot;, &quot;DST&quot;, &quot;tzdb&quot;, &quot;type&quot;, &quot;source&quot;)
\end{lstlisting}
\end{document}

“Latex ‘listings’ 不显示单引号和双引号内的代码。”

huangapple
  • 本文由 发表于 2023年5月20日 23:23:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定