Latex Listings Syntax Highlighting for Groovy and AspectJ

2013-07-08 20:56 by Thorben Bürgel

For my thesis I needed to highlight the syntax of Groovy and AspectJ with the listings package. These languages aren't supported by default and I haven't found sufficient definitions on the internet, thus I defined them by myself.
I want to share my solutions, so that others can use and improve them.

This is the code for AspectJ:

\definecolor{darkgray}{rgb}{.4,.4,.4}

\lstdefinelanguage{AspectJ}[]{Java}{
	morekeywords={declare, pointcut, aspect, before, around, after, returning, throwing, call, execution, this, target, args, within, withincode, get, set, initialization, preinitialization, staticinitialization, handler, adviceexecution, cflow, cflowbelow, if, proceed},
	moredelim=[is][\textcolor{darkgray}]{\%\%}{\%\%},
	moredelim=[il][\textcolor{darkgray}]{§§}
}

This is the code for Groovy:

\definecolor{groovyblue}{HTML}{0000A0}
\definecolor{groovygreen}{HTML}{008000}
\definecolor{darkgray}{rgb}{.4,.4,.4}

\lstdefinelanguage{Groovy}[]{Java}{
  keywordstyle=\color{groovyblue}\bfseries,
  stringstyle=\color{groovygreen}\ttfamily,
  keywords=[3]{each, findAll, groupBy, collect, inject, eachWithIndex},
  morekeywords={def, as, in, use},
  moredelim=[is][\textcolor{darkgray}]{\%\%}{\%\%},
  moredelim=[il][\textcolor{darkgray}]{§§}
}

As you can see I also defined the color scheme for Groovy. I tried to imitate the Groovy console. But I didn't find any good automatic possibility to highlight numbers in red. Does Anybody know to do it? Tell me and I will include it.

I also added an option to manually highlight annotations with %% or $$. I found this snippet in this thread
http://tex.stackexchange.com/a/115562 on StackExchange.

By the way the code highlighting on my website doesn't support LaTex, sorry ;)

Go back