I am writing some code with the listings package and I need to detect the words starting with the number sign (#) and apply certain style. For example, if I have this code:
something #foo anotherThing
I would like to put blue colors to '#foo'.
So far I have:
\lstset{
....
identifierstyle=\idstyle,
}
And then:
\makeatletter
\newcommand*\idstyle{%
\expandafter\id@style\the\lst@token\relax
}
\def\id@style#1#2\relax{%
\ifcat#1\relax\else
\ifnum`#1=\uccode`#1%
\small\ttfamily\color{red!100!black}
\fi
\ifnum\pdfstrcmp{#1}{\#}=0
\small\ttfamily\color{blue!100!black}
\fi
\ifnum`#1= 35%
\small\ttfamily\color{blue!100!black}
\fi
\fi
}
\makeatother
So I am trying to put a blue color for words starting with #. The first try (using \pdfstrcmp) works perfect with others type of characters but not with #. I cannot scape it. I tried to scape # in lots of ways such as \#, \#\, |\verb#|, etc et, but no one worked.
In the second try, I am trying to go by comparing the unicode value, but I am not successful either.
Notice also that at the same time I wanted to put colors (different color) to words that start with uppercase. So how can I have both at the same time (set different colors to both, words that start with uppercase and those that start with \#?
Sorry for the question but I am newbie with Latex...
Any ideas how can I get this?


@. Unfortunately I can't find it now :( – Claudio Fiandrino Jun 02 '12 at 12:40