I'm trying to typeset some python code, and I would like integer literals to be highlighted. I've come up, after about two hours of fighting with the documentation and various other questions here and on SO, with the following:
\lstset{ %
language=Python,
otherkeywords={1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
morekeywords=[2]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
keywordstyle=[2]{\color{orange}},
keywordstyle=\color{blue}\bfseries,
stringstyle=\color{red},
}
Unfortunately, that doesn't work. Numbers found in strings are also highlighted, which is rather annoying, and not only are they highlighted: they are highlighted in blue. Numerals in regular program text, on the other hand, are rightly highlighted in red.
Help?
EDIT: Thanks Peter Grill for your very nice solution. Is there a way to not break string colouring, though? When I use you code, the stringstyle=\color{red} doesn't seem to work anymore (strings are just plain black). Similarly, comments can be enclosed in triple quotes in python, and if I adapt your quote to detect """ blocks, then the corresponding
comments are not highlighted anymore.


\documentclassand the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Nov 15 '11 at 16:53\documentclassand the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Nov 20 '11 at 16:02