In relation to my comment. You can use the option literate only for the brackets.
\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,graphicspath},%
mathescape=false,escapechar=|,%
literate={<B>}{\textcolor{blue}{\string\usepackage}}1
{\{ }{\textcolor{red}{\{}}1
{\}}{\textcolor{red}{\}}}1
{[}{\textcolor{green}{[}}1
{]}{\textcolor{green}{]}}1
}
\pagestyle{empty}
\begin{document}
\begin{lstlisting}
\documentclass[12pt]{article}
<B>{xcolor}
<B>{listings}
<B>[options]{graphicx}
\graphicspath{{img/pdf}}
\begin{document}
Text
\end{document}
\end{lstlisting}
\end{document}
Since you want to customize (La)TeX, it's a good idea to set texcsstyle
to have the same color as the keywords and to use the star so that the backslash will also have the same color; regarding your issue, the braces are not really keywords; I set their style (and also for the square brackets) using literate
(notice the *
character in the first literate line to prevent color form appearing in comments and strings):
\documentclass{scrreprt}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\definecolor{keywords}{HTML}{8A4A0B}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{comments}{HTML}{868686}
\definecolor{myblue}{RGB}{20,105,176}
\lstset{language=[LaTeX]Tex,
keywordstyle=\color{keywords},
texcsstyle=*\color{keywords},
basicstyle=\normalfont\ttfamily,
commentstyle=\color{comments}\ttfamily,
stringstyle=\rmfamily,
numbers=left,
numberstyle=\scriptsize,
stepnumber=1,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frameround=ftff,
frame=lines,
morekeywords={RequirePackage,ProvidesPackage,NeedsTeXFormat},
backgroundcolor=\color{background},
literate=
*{\{}{{\textcolor{myblue}{\{}}}{1}
{\}}{{\textcolor{myblue}{\}}}}{1}
{[}{{\textcolor{myblue}{[}}}{1}
{]}{{\textcolor{myblue}{]}}}{1},
}
\begin{document}
\begin{lstlisting}[firstnumber=1]
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{arsclassica}[2012/02/21 v4.0 Customizing ClassicThesis (LP)]
\RequirePackage{classicthesis}
\RequirePackage{caption}% Caption package
\end{lstlisting}
\end{document}
To answer your specific question, you can use [<number>]
both in keywordstyle
and in keywords
, to define different keyword sets with their own style; a little example
\documentclass{scrreprt}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\definecolor{keywords}{HTML}{8A4A0B}
\definecolor{background}{HTML}{EEEEEE}
\lstset{language=[LaTeX]Tex,
keywordstyle=\color{keywords},
keywordstyle=[2]\color{red},
keywordstyle=[3]\color{orange},
basicstyle=\normalfont\ttfamily,
showstringspaces=false,
frameround=ftff,
frame=lines,
morekeywords={RequirePackage,ProvidesPackage},
keywords=[2]{Some,Other,Keywords},
keywords=[3]{and,another,test},
backgroundcolor=\color{background}
}
\begin{document}
\begin{lstlisting}[firstnumber=1]
\NeedsTeXFormat{LaTeX2e}
Some Other Keywords
and another test
\end{lstlisting}
\end{document}
To apply color to lengths, one can escape to LaTeX (this however won't work for in-line listings):
\documentclass{scrreprt}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\definecolor{keywords}{HTML}{8A4A0B}
\definecolor{background}{HTML}{EEEEEE}
\definecolor{comments}{HTML}{868686}
\definecolor{lengthcolor}{RGB}{200,40,150}
\definecolor{myblue}{RGB}{20,105,176}
\lstset{language=[LaTeX]Tex,
keywordstyle=\color{keywords},
texcsstyle=*\color{keywords},
basicstyle=\normalfont\ttfamily,
commentstyle=\color{comments}\ttfamily,
stringstyle=\rmfamily,
numbers=left,
numberstyle=\scriptsize,
stepnumber=1,
numbersep=8pt,
showstringspaces=false,
breaklines=true,
frameround=ftff,
frame=lines,
morekeywords={RequirePackage,ProvidesPackage,NeedsTeXFormat,setlength},
backgroundcolor=\color{background},
literate=
*{\{}{{{\color{myblue}{\{}}}}{1}
{\}}{{{\color{myblue}{\}}}}}{1}
{[}{{{\color{myblue}{[}}}}{1}
{]}{{{\color{myblue}{]}}}}{1},
escapeinside=!!
}
\newcommand\lencolor[1]{\textcolor{lengthcolor}{\texttt{#1}}}
\begin{document}
\begin{lstlisting}[firstnumber=1]
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{arsclassica}[2012/02/21 v4.0 Customizing ClassicThesis (LP)]
\RequirePackage{classicthesis}
\RequirePackage{caption}% Caption package
\setlength\parskip{!\lencolor{18pt}!}
\hspace*{!\lencolor{15cm}!}
\end{lstlisting}
\end{document}
Best Answer
You can use
keywords=[2]{...}
,keywordstyle=[2]
for a second group of keywords with different style (in this case, for the keywords in orange color); usingotherkeywords=
you can use the blue color forWIDTH
: