[Tex/LaTex] Change Character Color in listing

colorlistings

I want to change some special character's color in listing for example all Parenthesis be red. I don't want to make them keywords they should have different color. is it possible?

Best Answer

You could use the literate key; in the following example. parentheses are typeset in red:

\documentclass{article}
\usepackage{listings} 
\usepackage{xcolor}

\lstset{
    basicstyle=\small\ttfamily,
    columns=fullflexible,
    literate=*{(}{{\textcolor{red}{(}}}{1}
         {)}{{\textcolor{red}{)}}}{1},
    }
\begin{document}

\begin{lstlisting}
    {
      _SetCalibTableName("lorem",100);
      g_Met_strReferenceName1=Met_strReferenceName;
    }
\end{lstlisting}

\end{document}

enter image description here