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.

How do I make comments highlighted in the form:

<!-- ======= Processing Root tag =======   -->

. This is not working.

\documentclass[11pt]{scrartcl}
\usepackage{listings, color}

\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

\lstloadlanguages{XML}

\lstdefinelanguage{XML}
{
  morestring=[b]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  morecomment=[s][\color{orange}]{<!--}{-->},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type}
}

\lstdefinestyle{listXML}{language=XML, extendedchars=true,  belowcaptionskip=5pt, xleftmargin=1.8em, xrightmargin=0.5em, numbers=left, numberstyle=\small\ttfamily\bf, frame=single, breaklines=true, breakatwhitespace=true, breakindent=0pt, emph={}, emphstyle=\color{red}, basicstyle=\small\ttfamily, columns=fullflexible, showstringspaces=false, commentstyle=\color{gray}\upshape}

\begin{document}
 XSLT listing:
 \begin{lstlisting}[style=listXML]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     version="1.0">
<!-- ======= Processing Root tag =======   -->
<xsl:template match="Root">
    <TeXML>
      <TeXML escape="0">
                \documentclass[14pt]{extarticle}
                \usepackage[T2A]{fontenc}
                \usepackage{pscyr}
                \usepackage[cp1251]{inputenc}
                \usepackage[english,russian]{babel}
                \usepackage{longtable}
                \usepackage[a4paper, left=30mm, right=15mm, top=20mm, bottom=20mm]{geometry}
                \usepackage{indentfirst}
                \usepackage{fixltx2e}
         </TeXML>
      <env name="document">
        <cmd name="clearpage"/>
        <xsl:apply-templates select="BasicInfo | StatusInfo"/>
      </env>
    </TeXML>
  </xsl:template>
  <!-- ======= Types of opening ====== -->
  <xsl:template match="ConsDescr">
    <cmd name="par"/>
    <cmd name="textbf">
....
\end{lstlisting}
 \end{document}
share|improve this question
    
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 16 at 3:02

1 Answer 1

The problem is that the following two lines in your \lstdefinelanguage{XML} are in conflict:

morestring=[s]{>}{<},
morecomment=[s][\color{orange}]{<!--}{-->},

In addition, doesn't \lstdefinelanguage{XML} redefine the XML language settings, thereby losing a lot of configs? One of the most noticeable drawbacks is that you can no longer access tagstyle, while the identifierstyle setting would highlight both tag names and contents (the embedded LaTeX code).

Would it be feasible for you to move all the settings into \lstdefinestyle instead, dropping morestring=[s]{>}{<}, and using tagstyle in place of identifierstyle?

\lstdefinestyle{listXML}{language=XML, extendedchars=true,  belowcaptionskip=5pt, xleftmargin=1.8em, xrightmargin=0.5em, numbers=left, numberstyle=\small\ttfamily\bf, frame=single, breaklines=true, breakatwhitespace=true, breakindent=0pt, emph={}, emphstyle=\color{red}, basicstyle=\small\ttfamily, columns=fullflexible, showstringspaces=false, commentstyle=\color{gray}\upshape,
morestring=[b]",
morecomment=[s]{<?}{?>},
morecomment=[s][\color{orange}]{<!--}{-->},
keywordstyle=\color{cyan},
stringstyle=\color{black},
tagstyle=\color{darkblue},
morekeywords={xmlns,version,type}
}

This is the output I got:

enter image description here

share|improve this answer
    
Thank you. It works. –  Youra_P Jul 2 '12 at 17:37
1  
@Youra_P You're welcome. :-) If this answer has solved your problem, it would be much appreciated if you could "accept" it by clicking the tick mark next to it (you may have to mouse-over the upvote count area to see it). Only when there is an accepted answer (even if it's the only answer given), will a question be deemed "answered" on stackexchange. –  LianTze Lim Jul 3 '12 at 2:47

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.