LaTeX listings package: different style for constants/classes/variables
I'm using the listings
package for syntax highlighting, set up with the following arguments:
\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{d开发者_如何学运维arkgreen},
stringstyle=\color{red}
}
This works fairly well, resulting in:
What I would like, is that the constants MIN_PIXELS
and MAX_PROCESSING_TIME
are styled in a different color, and the class names Rectangle
, Bitmap
, etc. are styled in yet another color. It would also be nice if I could get numbers colored, but that's not my main focus.
Is there any way to do this?
Listings only works by keywords, so it is not possible.
Minted uses a python library (Pygments) and can do any kind of highlighting as it is able to understand the code and not just keywords.
From documentation of listings (page 20ff.): \lstset{morecomment=[s][\color{blue}]{/*+}{*/},
morecomment=[s][\color{red}]{/*-}{*/}}
You can try to set morekeywords
and give a specific keyword the right color.
精彩评论