LaTeX listings package: different style for constants/classes/variables

Paul Lammertsma picture Paul Lammertsma · Jul 14, 2010 · Viewed 8k times · Source

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{darkgreen},
  stringstyle=\color{red}
}

This works fairly well, resulting in:

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

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?

Answer

Cloudanger picture Cloudanger · Jul 15, 2010

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.