6

I use the listings package and I want to override an attribute of the HTML style.

Unfortunately my code overrides the whole HTML style and not just a single property:

\lstloadlanguages{HTML}
\lstdefinelanguage{HTML}{ndkeywords={charset, window, document}}

Does anyone know how I can only override ndkeywords?

5

Package listings allows the definition of styles, there you can put the options to format the special HTML code listings. Also the keywords, which should be displayed differently, needs to be removed from the default class first. Then the example adds these keywords to class 2 and avoids the use of ndkeywords, because this is marked deprecated in the documentation of listings.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[variablett]{lmodern}
\usepackage{color}
\usepackage{listings}
\lstset{
  columns=fullflexible,
  basicstyle=\ttfamily,
}
\lstdefinestyle{myHTML}{
  language=HTML,
  keywordstyle=\color{blue},
  deletekeywords={charset, document, window},
  morekeywords={[2]{charset, document, window}},
  keywordstyle={[2]{\color{red}}},
}

\begin{document}
\begin{lstlisting}[style=myHTML]
<HTML>
  <HEAD></HEAD>
  <BODY>
    <A href="http://tex.stackexchange.com"
       charset="US-ASCII">TeX.SE</A>
  </BODY>
</HTML>
\end{lstlisting}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.