3

I am trying to typeset a makefile using listings.

Now I would like some differential highlighting, e.g. for variables and ordinary commands in the target body. In this snippet, want to have different highlighting for VAR and for rm -rf, but it seems the only classes one can style are identifierstyle, stringstyle and keywordstyle. The latter is hardly useful and only highlights builtins (obviously), but identifierstyle applies to basically everything, making it utterly useless here.

\documentclass{scrartcl}
\usepackage{listings}
\begin{document}
\lstset{language=[gnu] make}
\lstset{
   language=[gnu] make,
   keywordstyle=\color{teal}\textbf,
   stringstyle=\color{blue},
   identifierstyle=\itshape
}
\begin{lstlisting}
VAR=foo
clean:
   rm -rf $(VAR)
\end{lstlisting}
\end{document}

Can anyone suggest either an explanation for why this is so (what use is the language definition for make if there's no way around it?), or why it should be so, or – preferably – a workaround that does not involve manually specifying e.g. keywords?

EDIT: I had some success with morecomment=[n]{$(}{)}, but it is crude and prevents actual comment highlighting. Also that does not highlight VAR when not surrounded by parentheses. Is there a way to define different classes of comments which can be differentially highlighted?

Your Answer

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

Browse other questions tagged or ask your own question.