6

With this code

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

\lstset{%
  language=[AlLaTeX]TeX,
  alsolanguage=MetaPost,
  texcsstyle=\color{blue},
  basicstyle=\ttfamily%
}

\begin{document}
\begin{lstlisting}
 $\sum_{n=1}^\infty\frac{1}{n^2}$.
\end{lstlisting}
\end{document}

the \sum is not colored. But, if I replace MetaPost by pstricks, \sum turns into blue.

Someone could help me and explain the problem?

5

From the listings package documentation:

Bug: texcs... interferes with other keyword lists. If, for example, emph contains the word foo, then the control sequence \foo will show up in emphstyle.

Based on this I tried to declare MetaPost first and TeX second, and it worked.

Code

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

\lstset{%
    language=MetaPost,
    alsolanguage=[AlLaTeX]TeX,
    texcsstyle=\color{blue},
    basicstyle=\ttfamily%
}

\begin{document}
    \begin{lstlisting}
    $\sum_{n=1}^\infty\frac{1}{n^2}$.
    \end{lstlisting}
\end{document}

You can also use a starred variant of texcsstyle to also highlight the backslash:

texcsstyle=*\color{blue}

Result

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.