Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

enter image description here

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,
    commentstyle=\color{gray}\upshape,
    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>
    <heading>Reminder</heading>
    <body>Dont forget me this weekend!</body>
</note>
\end{lstlisting}

\end{document}
share|improve this question
    
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
add comment

migrated from stackoverflow.com Oct 19 '12 at 10:09

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

1 Answer

up vote 1 down vote accepted

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

otherkeywords={attribute=, xmlns=}

enter image description here

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,
    commentstyle=\color{gray}\upshape,
    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>
    <heading>Reminder</heading>
    <body>Dont forget me this weekend!</body>
</note>
\end{lstlisting}

\end{document}
share|improve this answer
    
Well I don´t understand why but it works, thanks a lot man! Now it finally looks like Oxygen. –  chris Oct 20 '12 at 8:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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