我正在使用 listings 用于语法突出显示的包,使用以下参数进行设置:

\lstset{
  language=Java,
  captionpos=b,
  tabsize=3,
  frame=lines,
  numbers=left,
  numberstyle=\tiny,
  numbersep=5pt,
  breaklines=true,
  showstringspaces=false,
  basicstyle=\footnotesize,
  identifierstyle=\color{magenta},
  keywordstyle=\bfseries,
  commentstyle=\color{darkgreen},
  stringstyle=\color{red}
}

这效果相当好,结果是:

(screenshot 1 of resulting document) (screenshot 2 of resulting document)

我想要的是常数 MIN_PIXELSMAX_PROCESSING_TIME 以不同的颜色设计样式,并且类名称 Rectangle, Bitmap, , ETC。采用另一种颜色设计。如果我能把数字涂上颜色那就太好了,但这不是我的主要关注点。

有什么办法可以做到这一点吗?

有帮助吗?

解决方案

来自列表文档(第 20 页): \lstset{morecomment=[s][\color{blue}]{/*+}{*/}, morecomment=[s][\color{red}]{/*-}{*/}}你可以尝试设置 morekeywords 并为特定关键字指定正确的颜色。

其他提示

列表只能通过关键字起作用,所以这是不可能的。

铸造 使用 python 库(Pygments)并且可以进行任何类型的突出显示,因为它能够理解代码而不仅仅是关键字。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top