1

Consider the following valid XML according to https://stackoverflow.com/a/1478623/1443496?

\documentclass{article}
\usepackage{listings}
\lstset{
  language=xml,
  morekeywords=some-tag,
}
\begin{document}
\begin{lstlisting}
<some-tag>
  text
</some-tag>
\end{lstlisting}
\end{document}
0

1 Answer 1

2

By default, the hyphen is of type "other" (see Table 2: Standard character table on page 45 of the listings package documentation), so you cannot directly use it in keywords; you can change its status to "digit" (or to "letter") first:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
  language=xml,
  alsodigit={-},
  keywordstyle=\color{red},
  morekeywords={some-tag},
}
\begin{document}
\begin{lstlisting}
<some-tag>
  text
</some-tag>
\end{lstlisting}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .