listings排源代码,如何让反斜杠高亮显示?z

原文地址:http://bbs.chinatex.org/forum.php?mod=viewthread&tid=7282&extra=page%3D1

原始出处:http://tex.stackexchange.com/questions/17774/listings-package-can-i-include-a-backslash-in-language-keyword-begin-for

latex-listings-1

latex-listings-1

如第一幅图所示,高亮的结果是有问题的,也不太好看,实际,我们需要用texcsstyle来设置即可,有关该指令的作用参考listings宏包的手册或http://www.chinatex.org/archives/620,这里的cs即控制序列。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[scaled=0.82]{beramono}
\usepackage{listings,xcolor}
\begin{document}
\begin{lstlisting}[basicstyle=\small\ttfamily,language={[LaTeX]TeX},
texcsstyle=*\color{red}\bfseries,
keywordstyle=\color{blue}\bfseries,
morekeywords=alignat,moretexcs=intertext]
\begin{alignat*}{4}
y &= -4 &+ 3 &+4 &-7 \\
y &= &+ 3 & &-7 \\
\intertext{Therefore}
a &= b &d &= cccc &e &= d \\
a &= bbbb &d &= c &e &= d
\end{alignat*}
\end{lstlisting}
\end{document}

正确的演示效果如下图所示:

latex-listings-2

latex-listings-2

0%