TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For my project, I've been using the listings package in order to color the keywords, comments, strings, and digits in the code.

The thing is, I've managed to color the keywords, comments and strings, however, I couldn't color the digits within the code without coloring those in the comments/strings.

I've tried using the solution proposed in Coloring digits with the listings package; however, it didn't work. The digits weren't colored in the strings, but they were in the comments.

Would you be kind to suggest me a solution?

share|improve this question
Welcome to TeX.SE. It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Jan 6 '12 at 19:02
We don't even know the syntax of your code so it will be pretty hard for us to help. – someonr Jan 7 '12 at 1:09
Did you read this question which is link the the one you found already? If that doesn’T help too, please add an MWE as Peter said. – Tobi Jan 9 '12 at 16:02
Solution at tex.stackexchange.com/a/163911/21891. – Jubobs Mar 6 '14 at 0:54

Based on “Listings package: How can I format all numbers?” I build this code




             {.0}{{\textcolor{blue}{.0}}}{2}% Following is to ensure that only periods
             {.1}{{\textcolor{blue}{.1}}}{2}% followed by a digit are changed.
   basicstyle=\ttfamily,%  Optional to use this


Text ... 123 4.5 % 123 comment

The trick is to let the commentstyle disable the \textcolor command.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.