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?

1 Answer 1

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

1
  • thanks. I'll try this afternoon :) Commented Oct 17, 2019 at 12:48

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.