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 need to highlight syntax in my LaTeX presentation, so i've found this answer: XML syntax highlighting

\lstdefinelanguage{XML}
{
  morestring=[b]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type},
  backgroundcolor=\color{lightgray},
  numbers=left,
  numberstyle=\footnotesize\ttfamily\color{gray},
  numbersep=0.5pt
}

Unfortunately i didn't found any way, how to specify extra style for text in attributes.

For example:

<xml>
    <person age="22" sex="female">Ann</person>
</xml>

It the case above, Ann and 22, female would have the same style... how to separate styles for those two things?

share|improve this question
    
Has there been any development on this yet? Does the answer provided help any or not? –  Edd Apr 6 '11 at 7:56
    
@Edd I'm sorry, i've already ran the presentation without using your advice, anyway, i'll take a look at it soon and if it help, i swear, i'll give you an upvote/accept-question-mark. I'm busy right now, just give me few more days... –  Radek Simko Apr 6 '11 at 8:36
    
Absolutely no problem. I was just curious as to whether this fixed your problem or whether there was something deeper to investigate. I'm not so fussed about the upvote/answer to be honest! –  Edd Apr 6 '11 at 9:30
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Jan 15 at 23:35
add comment

2 Answers 2

When you add the color package and change

morestring=[b]",

into

morestring=[b][\color{red}]",

the attributes will color red.

This will color the attributes red in your xml listings.

\begin{lstlisting}[language=xml, frame=single]
<xml>
    <person age="22" sex="female">Ann</person>
</xml>
\end{lstlisting}

enter image description here

\documentclass{article}

\usepackage{listings}
\usepackage{color}
\definecolor{lightgray}{rgb}{.7,.7,.7}
\definecolor{gray}{rgb}{.4,.4,.4}
\definecolor{darkblue}{rgb}{0,0,.3}
\begin{document}

\begin{lstlisting}[language=xml, frame=single]
<xml>
    <person age="22" sex="female">Ann</person>
</xml>
\end{lstlisting}

 \lstdefinelanguage{XML}
{
  morestring=[b][\color{red}]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type},
  backgroundcolor=\color{lightgray},
  numbers=left,
  numberstyle=\footnotesize\ttfamily\color{gray},
  numbersep=0.5pt
}

\begin{lstlisting}[language=xml, frame=single]
<xml>
    <person age="22" sex="female">Ann</person>
</xml>
\end{lstlisting}

\end{document}




 \lstdefinelanguage{XML}
{
  morestring=[b][\color{red}]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type},
  backgroundcolor=\color{lightgray},
  numbers=left,
  numberstyle=\footnotesize\ttfamily\color{gray},
  numbersep=0.5pt
}
share|improve this answer
add comment

The minted package produces code which has tag-names, attribute-names, attribute-values and tag-contents printed differently, so the following code would produce the output which follows it:

\documentclass{minimal}
\usepackage{minted}
\begin{document}
\begin{minted}{xml}
    <xml>
        <person age="22" sex="female">Ann</person>
    </xml>
\end{minted}
\end{document}

Screenshot of sample minted XML output

Note, however, that the minted package use a python program called pygments, which is fairly straightforward to install as detailed in the minted documentation.

share|improve this answer
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.