lstlisting code is blue instead of black - keywordstyle taking over?

2.1k views Asked by At

When using lstlisting and certain parameters, (most) code turns blue, even though it should only be keywords and identifiers, while the rest should have a black color. For good measure, the rest of text in document is black :-)

Preferably the keywords should also be bold as well, but I've found out that might be a font problem, but I can't figure out how to change lstlisting font without changing font for the whole document.

Thanks for your time!

\lstset{language={[Sharp]C},
basicstyle=\color{black}\ttfamily\scriptsize,
numbers=left,
numberstyle=\tiny,
numbersep=3pt,
tabsize=1,
extendedchars=true,
breaklines=true,
keepspaces=true,
showspaces=false,
showtabs=false,
xleftmargin=5pt,
framexleftmargin=5pt,
framexrightmargin=5pt,
framexbottommargin=4pt,

morecomment=[l]{//}, %use comment-line-style!
morecomment=[s]{/*}{*/}, %for multiline comments
showstringspaces=false,
commentstyle=\color{black},
keywordstyle=\color{blue}\bfseries,
identifierstyle=\color{blue}\bfseries,
backgroundcolor=\color{almostwhite},
}

Below is code sample in compiled PDF:

Blue Code

1

There are 1 answers

0
nsaura On BEST ANSWER

I don't know if the problem has been solved but it seems your language C Sharp is not known is the predefined languages here p.12 tab 1.

You can create your own language by using lstdefinelanguage see here for an example of how it works