我正在使用 Listings,并且希望忽略字符串中的关键字。例如,我的示例中的代码突出显示了if
字符串中的关键字:
\documentclass{article}
\usepackage{listings}
%define Javascript language
\lstdefinelanguage{JavaScript}{
keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break},
keywordstyle=\color{niceblue}\bfseries,
ndkeywords={class, export, boolean, throw, implements, import, this, return},
ndkeywordstyle=\color{purple}\bfseries,
identifierstyle=\color{black},
sensitive=false,
comment=[l]{//},
morecomment=[s]{/*}{*/},
commentstyle=\color{pink}\ttfamily,
stringstyle=\color{darkyellow}\ttfamily,
morestring=[b]',
morestring=[b]"
}
\lstset{
language=JavaScript,
extendedchars=true,
basicstyle=\footnotesize\ttfamily,
showstringspaces=false,
showspaces=false,
numbers=left,
numberstyle=\footnotesize,
numbersep=9pt,
tabsize=2,
breaklines=false,
showtabs=false,
captionpos=b,
upquote=true,
}
\begin{document}
\begin{lstlisting}[language=JavaScript]
console.log("lorem if ipsum");
\end{lstlisting}
\end{document}
morestring=**[d]{'},
我按照所推荐的方式尝试 ,但并没有改变任何事情。