I'm wondering, does listings allow you to define your own syntax highlighting, and if so, how sophisticated is its system?

Here's a minimal example:



    foo(Arg1, Arg2) :-
      length([1,2,3], 3).

Ideally, in the following code sample, "foo" would be highlighted (since it's declaring a new clause), as would ":-".

I tried to use emph and morekeywords to highlight :-, but neither worked. They seems to work for regular words like "for" and "while", but not for the sequence ":-". Is there a special way to escape this to add a keyword?

To highlight the name of the predicate before :-, I have no idea how I would tackle that. It's not essential, but it would be nice if I could get it working. Can I define custom syntax/grammar for highlighting Prolog?


1 Answer 1


Not quite a direct answer to your question, but I recommend the rather wonderful package minted. It uses pygments to highlight a wide variety of languages. Keep in mind that you'll need to pass -shell-escape to latex so that it can call out to pygments. Documentation here (pdf).

Frankly, I switched to minted because setting up anything complex in listings quickly got out of hand for my tastes.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .