# \lstset colorize numbers in code [duplicate]

I defined a syntax highlighting for my code like so:

\lstdefinelanguage{CSharp}{
sensitive = true,
keywords={assembly, class, method, field},
keywords=[2]{public, private, family, assembly, famandassem, famorassem, nested, static, abstract, virtual, hidebysig, cil, managed, specialname, rtspecialname, interface, sealed, auto, ansi, unicode, beforefieldinit, sequential, explicit},
keywords=[3]{class, void, string, int, object, if, else, if, switch, break, case, boo, while, truel},
keywordstyle=\color{forestgreen},
keywordstyle=[2]\color{purple},
keywordstyle=[3]\color{blue},
numbers=left,
numberstyle=\scriptsize,
stepnumber=1,
numbersep=8pt,
xleftmargin=2em,
framexleftmargin=1.5em,
showstringspaces=false,
breaklines=true,
frame=single,
basicstyle=\ttfamily,
comment=[l]{//},
morecomment=[s]{/*}{*/},
stringstyle=\color{maroon},
morestring=[b]',
morestring=[b]"
}

\definecolor{forestgreen}{rgb}{0.13, 0.55, 0.13}
\definecolor{maroon}{rgb}{0.5, 0.0, 0.0}

\newcommand{\sourcecode}[3]{\vspace{10pt}\lstinputlisting[language=CSharp, label={#2}, caption={#3}, captionpos=b, abovecaptionskip=10pt]{#1}}


It works nicely but I can't change the colors of numbers in the code. When I add them to the keyword list they are simply ignored. And modifying the numberstyle only affects the line numbers but not the numbers in the code:

How can I set custom color highlighting for numbers in the code, such as the 0 and the 3?

## marked as duplicate by siracusa, Raaja, Zarko, schtandard, Stefan PinnowJun 22 at 8:20

• Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. – Andrew Jun 22 at 0:30