开发者

Latex listings strings and keywords

开发者 https://www.devze.com 2023-01-27 10:16 出处:网络
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 bu

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 diffre开发者_如何学编程nt 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.


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


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. :-()


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消