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}
Best Answer
The problem is that the following two lines in your
\lstdefinelanguage{XML}
are in conflict: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 accesstagstyle
, while theidentifierstyle
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, droppingmorestring=[s]{>}{<}
, and usingtagstyle
in place ofidentifierstyle
?This is the output I got: