# \lstdefinestyle syntax highlighting

I´m new to latex and got the following problem. I defined a listing style for XML Syntax highlighting like this:

How can I get also the equals symbol in the attribute color (orange)? I want to do sth. like this

\lstdefinestyle{XML}{
morekeywords={xmlns=,attribute\equals}
}


is there some kind of escape sequence to achieve this, or is it not possible?

Here you go:

\documentclass[a4paper, 12pt]{article}

\usepackage{listings, color}

\definecolor{forestgreen}{RGB}{34,139,34}
\definecolor{orangered}{RGB}{239,134,64}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{gray}{rgb}{0.4,0.4,0.4}

\lstdefinestyle{XML} {
language=XML,
extendedchars=true,
breaklines=true,
breakatwhitespace=true,
emph={},
emphstyle=\color{red},
basicstyle=\ttfamily,
columns=fullflexible,
morestring=[b]",
morecomment=[s]{<?}{?>},
morecomment=[s][\color{forestgreen}]{<!--}{-->},
keywordstyle=\color{orangered},
stringstyle=\ttfamily\color{black}\normalfont,
tagstyle=\color{darkblue}\bf,
morekeywords={attribute,xmlns,version,type,release},
}

\begin{document}

\begin{lstlisting}[style=XML]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<note attribute="main" xmlns="http://www.w3.org/1999/xhtml">
<to>Tove</to>
<from>Jani</from>
<body>Dont forget me this weekend!</body>
</note>
\end{lstlisting}

\end{document}

-

## migrated from stackoverflow.comOct 19 '12 at 10:09

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Oct 19 '12 at 15:29

One way to do achieve this would be to define otherkeywords for these cases.

otherkeywords={attribute=, xmlns=}


## Code:

\documentclass[a4paper, 12pt]{article}

\usepackage{listings, color}

\definecolor{forestgreen}{RGB}{34,139,34}
\definecolor{orangered}{RGB}{239,134,64}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{gray}{rgb}{0.4,0.4,0.4}

\lstdefinestyle{XML} {
language=XML,
extendedchars=true,
breaklines=true,
breakatwhitespace=true,
emph={},
emphstyle=\color{red},
basicstyle=\ttfamily,
columns=fullflexible,
morestring=[b]",
morecomment=[s]{<?}{?>},
morecomment=[s][\color{forestgreen}]{<!--}{-->},
keywordstyle=\color{orangered},
stringstyle=\ttfamily\color{black}\normalfont,
tagstyle=\color{darkblue}\bf,
morekeywords={attribute,xmlns,version,type,release},
otherkeywords={attribute=, xmlns=},
}

\begin{document}

\begin{lstlisting}[style=XML]
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<note attribute="main" xmlns="http://www.w3.org/1999/xhtml">
<to>Tove</to>
<from>Jani</from>

I'm getting Package keyval Error: tagstyle undefined. – maja May 3 '15 at 9:20
@maja: I just tested it now and it seems to work for me. I suspect your packages are not up to date. You could either try to update packages one at a time or just get TeXLive2014 and update ALL the packages to the latest version (which is what I would recommend). Alternatively, you could post a new question and include the output of \listfiles. – Peter Grill May 6 '15 at 16:38