I'm trying to show some c++ codes and want to hightlight all the literal digits with colors. I have referred to the question Coloring digits with the listings package and Colored strings by listings package, but I still have two more requirements.

First, the names of variates are colored. Consider the following code:

int t1=0;

When using the code:


Then the 1 in t1 is colored.

Still, there are also some attribute in the literals, such as:

unsigned t0=0u;
unsigned long long t1=314159ull;
int t2=0x14;
float t3=1e-3f;

Can these attributes be recognized and colored?

Maybe the second requirement is too demanding. However, the first one is what I must solve.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.