4

Why square bracket does not appear in green in the second example ?

\documentclass[11pt, oneside]{article}  

\usepackage{listings}
\usepackage{xcolor}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\newcommand{\CodeSymbol}[1]{\textcolor{darkgreen}{#1}}

\lstset{
  language=[LaTeX]{TeX},
  }

 \lstdefinestyle{myLangStyleA}{
    literate={\{}{{\CodeSymbol{\{}}}1
}

\lstdefinestyle{myLangStyleB}{
    literate={\{}{{\CodeSymbol{\{}}}1
          {\[}{{\CodeSymbol{\[}}}1, 
}

\begin{document}

\begin{lstlisting}[style=myLangStyleA]
[ {
\end{lstlisting}

\begin{lstlisting}[style=myLangStyleB]
[ {
\end{lstlisting}

\end{document}  

Which produces this result :

Green square bracket does not appear

Thanks !

0

1 Answer 1

4

The bracket [ is not a special character, so you should simply use it as is.

\documentclass[11pt, oneside]{article}  

\usepackage{listings}
\usepackage{xcolor}
\definecolor{darkgreen}{rgb}{0,0.6,0}
\newcommand{\CodeSymbol}[1]{\textcolor{darkgreen}{#1}}

\lstset{
  language=[LaTeX]{TeX},
}

\lstdefinestyle{myLangStyleA}{
  literate={\{}{{\CodeSymbol{\{}}}1
}

\lstdefinestyle{myLangStyleB}{
  literate={\{}{{\CodeSymbol{\{}}}1
           {[}{{\CodeSymbol{[}}}1, 
}

\begin{document}

\begin{lstlisting}[style=myLangStyleA]
[ {
\end{lstlisting}

\begin{lstlisting}[style=myLangStyleB]
[ {
\end{lstlisting}

\end{document}  

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .