I tried to color a source code listing as follows. I would like the \ to be the same color as the word that follows for example:
\documentclass in red including "\"
\usepackage in blue including "\"
I would like brackets [ ] in green, but black text between them and { } and / in red, but the text within them in black and numbers in gray.
The file:
\documentclass[10pt]{article}
\usepackage{bera}
\usepackage{xcolor}
\usepackage{listings}
\lstset{basicstyle=\footnotesize\ttfamily,columns=flexible,frame=single,framerule=0pt,%
backgroundcolor=\color{gray!20},%
xleftmargin=\fboxsep,%
xrightmargin=\fboxsep,
language=[LaTeX]TeX,%
keywordstyle=\color{blue},%
texcsstyle=*\color{red}\bfseries,%
texcs={end,begin,documentclass},%
mathescape=false,escapechar=|,%
literate={<B>}{\textcolor{blue}{\string\usepackage}}1
{<P>}{\textcolor{blue}{\string\graphicspath}}1
{<I>}{\textcolor{green}{[}}1
{<D>}{\textcolor{green}{]}\normalcolor}1
{<$>}{\textcolor{red}{\{}\color{black}}1
{<$$>}{\textcolor{red}{\}}\normalcolor}1
}
\pagestyle{empty}
\begin{document}
\begin{lstlisting}
\documentclass<I>12pt<D><$>article<$$>
<B><$>xcolor<$$>
<B><$>listings<$$>
<B><I>options<D><$>graphicx<$$>
<P><$><$>img/pdf<$$><$$>
\begin<$>document<$$>
Text
\end<$>document<$$>
\end{lstlisting}
\end{document}
I should add (if possible), my idea is to get a text colored similarly to Texmaker.
The output
I only need color / and numbers. One more query, do I add a literate for every word you want in blue? Thanks

\lstsetcommand is defined in. You should provide a full minimal example. By providing it, you increase the chances that people are willing to have a look at your question and this increases the change that you will get an answer. – Marc van Dongen Feb 18 '12 at 16:11