views:

40

answers:

2

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?

+1  A: 

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.

qbi
Great suggestion, I'll give it a swing. I would prefer a method based upon regular expressions, if that is at all possible, because otherwise I'd need to specify all class names and constants in `lstset`.
Paul Lammertsma
This works! I was able to highlight specific keywords; e.g. for `MIN_PIXELS` I used: `morecomment=[s][\color{darkblue}]{MIN_PIXELS}{\ }`
Paul Lammertsma
+2  A: 

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.

Cloudanger
Thanks for the suggestion. I was looking for a solution specifically for `listings`, but I'll consider `minted` in the future.
Paul Lammertsma
I was annoyed by some other problems with `listings`, so I, too, have switched to `minted`. It was a pain to install, but it is definitely worth it!
Paul Lammertsma