[Tex/LaTex] How to render Android listings with syntax highlighting

colorhighlightingjavalistingssyntax

I need to include the source code of a bigger Android project in the documentation written with LaTeX. Do you recommend any particular package that is capable of highlighting Java code and which also addresses the specific class types added by the Android framework?
My Android project has been developed with Eclipse.

Optional:

  • It would be also convenient if there is any package that reads the project structure with package names and folders and generates some kind of table of contents from it.
  • What is your opinion on the minted package that uses pygments as a syntax highlighter?

Best Answer

Seems like a job for either the listings or the minted packages; both are customizable and offer Java as one of the predefined languages.

Using listings you can define your own set of rules for syntax highlighting for Android (see Sections 3.2 and 4.18 Language definitions of the package documentation)); Android is not one of the predefined languages in minted either, so you will also have to define a new language.

Additionally, with each one of the packages you can easily produce a list of your listings using \lstlistoflistings (with listings) or \listoflistings (with minted), and you can input your code from external files using \lstinputlisting (with listings) or \inputminted (with minted).

Since minted uses Pygments, it provides far superior syntax highlighting compared to listings; on the other hand, listings offers automatic breaking of long lines and, as far as I know, this feature is not offered by minted.