Question

Hallo all,

I'm working on a latex document and I pull some code in with the listings package. I found some great stuff here on stackoverflow and i look really cool but there are two things I want but I don't know how to get.

I would like to see strings and keywords (clojure keywords not latex keywords) highlighted in my code (with highlighted I just mean a diffrent color or something. The patterns for string is "string" and a keyword is :keyword-name (so from :to the next space). Does anybody know how to do this.

Thanks for you anwsers.

Was it helpful?

Solution

I don’t believe listings is able to handle that. You can make it highlight strings (via the stringstyle optin), but not arbitrary tokens (which you would need for your keywords).

An alternative would be to use the minted package. Admittedly, its usage isn’t as straightforward since it relies on additional software (Pygments) to be installed, but on the plus side it ships with a ready-made lexer for Closure.

(If you download minted, use the tip version from the repository instead of the latest release, since the release is buggy. :-()

OTHER TIPS

Here is my package for support clojure in listings package. You can highlight keywords by using standard listings settings

The documentation for the listings package provides an example of defining your own language and specifying what its keywords are. The example begins:

\lstdefinelanguage{rock} {morekeywords={one,two,three,four,five,six,seven,eight,
nine,ten,eleven,twelve,o,clock,rock,around,the,tonight},

I don't have any experience using this feature, but I'm sure you'll be able to figure it out. You'll also have to ensure that you set keyword highlighting on for your listings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top