0

This question already has an answer here:

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]{/*}{*/},
    commentstyle=\color{forestgreen},
    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:

enter image description here

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 Pinnow Jun 22 at 8:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Possibly duplicate: tex.stackexchange.com/a/32176/31034 – ferahfeza Jun 21 at 21:02
  • 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
  • There are already several similar questions on this site, additionally to the one linked above this or this one. – siracusa Jun 22 at 5:52

Browse other questions tagged or ask your own question.