我需要在 LaTeX 演示文稿中突出显示语法,因此我找到了这个答案: XML 语法突出显示
\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
}
不幸的是,我没有找到任何方法,如何在属性中为文本指定额外的样式。
例如:
<xml>
<person age="22" sex="female">Ann</person>
</xml>
如果是上述情况,Ann
和22
,female
则会具有相同的风格...如何区分这两种事物的风格?
答案1
当你添加颜色包并改变
morestring=[b]",
进入
morestring=[b][\color{red}]",
属性将会变成红色。
这会使 xml 列表中的属性变成红色。
\begin{lstlisting}[language=xml, frame=single]
<xml>
<person age="22" sex="female">Ann</person>
</xml>
\end{lstlisting}
\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
}