1

I would like to colorize in a special color all my constant which are all in capital letters in my code and all my method variables which begin with an @.

Is it possible to use Regex to define keywords with listings package ? It will help me for a lot of things !

For example, I actually have in a \lstdefinestyle:

keywords=[3]{@someName,@anotherName,@aboutOneHundredMore}
keywords=[4]{SOME_NAME,ANOTHER_NAME,ABOUT_ONE_HUNDRED_MORE}

--> If I could replace this by:

keywords=[3]{/@.+/}
keywords=[4]{/[A-Z_]+/}

it will save me from a lot of work !

If not, is there another way to have all my constant in a special color without defining all of them one by one in a keywords list ?

I first think about using morecomment or moredelim for the @ part but the ending character is problematic: it can be a space, a dot or a lot of other characters...

3
  • 2
    It would be very nice. Unfortunately it seems almost impossible to do it. Probably with a package based on Pygments like minted it would be possible, by defining a suitable lexer.
    – egreg
    Jul 15, 2014 at 12:10
  • OK :'( Is there at least a way to define more than one ending for a morecomment ? For example: morecomment=[s][\color{Red}]{@}{\ ,.,]} or morecomment=[s][\color{Red}]{@}{\ }{.}{]}
    – Matthieu.P
    Jul 15, 2014 at 12:29
  • related: tex.stackexchange.com/questions/159246/…
    – jub0bs
    Jul 15, 2014 at 12:38

0

Browse other questions tagged or ask your own question.