如何使表单中的注释突出显示:
<!-- ======= Processing Root tag ======= -->
。这不起作用。
\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}
答案1
问题是您的以下两行\lstdefinelanguage{XML}
有冲突:
morestring=[s]{>}{<},
morecomment=[s][\color{orange}]{<!--}{-->},
此外,难道不\lstdefinelanguage{XML}
重新定义 XML 语言设置,从而丢失大量配置吗?最明显的缺点之一是您无法再访问tagstyle
,而identifierstyle
设置会突出显示标签名称和内容(嵌入的 LaTeX 代码)。
您是否可以将所有设置移至\lstdefinestyle
,删除morestring=[s]{>}{<}
,并使用tagstyle
代替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}
}
这是我得到的输出: