I want to write some LaTeX code and insert it in a snippet, so I used \lstset in my main code, like this:
\documentclass[11pt]{article}
\usepackage{listings}
\usepackage{color}
\lstset{
language=TeX,
backgroundcolor=\color{white},
basicstyle=\ttfamily,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=\usefont{T1}{pcr}{m}{sl}\color{red},
deletekeywords={},
escapeinside={\%},
firstnumber=1,
frame=leftline,
framerule=2.0pt,
keywordstyle=[1]\color{red}\ttfamily\bfseries,
morekeywords=[1]{\documentclass},
keywordstyle=[2]\color{blue}\ttfamily,
morekeywords=[2]{\begin, \end},
keywordstyle=[3]\color{green}\ttfamily,
morekeywords=[3]{\item},
numbers=left,
numbersep=10pt,
numberstyle=\tiny\color{red},
rulecolor=\color{black},
showstringspaces=false,
showtabs=false,
stepnumber=2,
stringstyle=\color{green},
tabsize=2,
}
\begin{document}
This is the snippet code:
\lstinputlisting{demo_code.tex}
According to this code, for example, "documentclass" should look like
{\color{red}$\backslash$documentclass} instead of $\backslash${\color{red}{documentclass}}
Likewhise, "begin" should look like {\color{blue}$\backslash$begin} instead of $\backslash$\color{blue}{begin}
\end{document}
And this is the demo code inserted in the main code:
\documentclass[12pt]{article}
\begin{document}
\begin{itemize}
\item this is the first item
\item this is the second item
\item this is the third item
\end{itemize}
\end{document}
So, the problem is that I don't know how to insert in the keywordstyle, commands with backslash symbol.
