1

How can I make every attribute name in color X and every element name in color Y without adding keywords and stuff?

What I did so far:

\lstdefinelanguage{myXML}
{
    morestring=[b]",
    morecomment=[s]{<?}{?>},
    morekeywords={
        name,
        type,
        targetNamespace,
        element,
        xmlns,
        xsd,
        s0,
        soap,
        http
    }
}

\lstdefinestyle{xmlStyle}{
    language=myXML,
    stringstyle=\color{mygreen},
    identifierstyle=\color{blue},
    keywordstyle=\color{mymauve},
}

What this results in:

enter image description here

As you can see, some of the element names (like xsd:something) are mauve instead of blue because they appear both as element and attribute name. Same with binding and element

1

It seems as if the problem is unsolvable with the listings-package. As recommended by @Marco Daniel I switched to the minted-package which works like a charm.

The installation was complicated but the instructions here helped me.

How to install syntax highlight package minted on Windows 7?

What all of these instructions where missing: You need to reboot after installing everything (at least that worked for me).

If you use TeXlipse (like me) and want to add the -shell-escape flag

Rightclick on Project > Properties > Latex Project Properties > Setup build tools... >
Select 'PdfLatex program' > Edit > Insert '-shell-escape' somewhere before '%input'

After that you can actually use minted.

I put this somewhere in the beginning (preamble) to make a reusable xml-style

\newminted[xml]{xml}{
    bgcolor = mygray,
    fontfamily = tt,
    fontsize = \scriptsize,
    gobble = 1,
    samepage
}

In my actual content I embedded XML like this

\begin{listing}[!ht]
  \begin{xml}
    <element attribute="value" />
  \end{xml}
  \caption[Test]{Just a test caption}
  \label{lst:test}
\end{listing}

The listing environment is to reference this piece of code later. If you are using \autoref{} you might find this helpful

\providecommand*{\listingautorefname}{Listing}

Thanks to Marco Daniel for showing me the minted-package :)

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.