In the following MWE the declared keywords te-st
and 999
are not highlighted as expected:
\documentclass{scrartcl}
\usepackage{listings,xcolor}
\lstdefinelanguage{mylang}{keywords={test,te-st,999,xyz},keywordstyle=\color{red}}
\begin{document}
\begin{lstlisting}[language=mylang,basicstyle=\ttfamily]
abc test
def te-st
ghi 999
jkl xyz
\end{lstlisting}
\end{document}
How can I define keywords like 999
or te-st
?
Best Answer
For listings, keywords like all identifiers start with letters and continue with letters or digits. If you need other characters in your identifiers, you must make them letters or digits. Alternatively, use the
otherkeywords
option for keywords consisting of characters you don't wish to redefine:See the Reference part of listings' documentation for details.