# listings package-How to highlight something that starts with one @

I would like to highlight any expression made of letters and that starts with one @. The use of moredelim=*[s][\color{blue}]{@}{\ } works only in case like @name is followed by one space. The following code nearly works except that I do not want the parenthesis to be colored in case like @decorator(x=3, y='some text') because that is @decorator( which is caught.

moredelim=[s][\bfseries\color{gray}]{@}{\ },
moredelim=[s][\bfseries\color{gray}]{@}{(},


The use of moredelim=[s][\bfseries\color{gray}]{@}{(} is not a good solution because the search is done one sevral lines... :-(

-
In text editors capable of regular expression identification, just search and highlight this string: ^@.*? But how is this a tex question? Do you want LaTeX to do this as it compiles? –  Ariel Apr 11 '12 at 16:38
listings is one LaTeX package. –  projetmbc Apr 11 '12 at 16:49
ah - thanks for the clarification and this is good to know. –  Ariel Apr 11 '12 at 17:19

This is possible. The package provides the command morecomments, which can be used to declare a sequence of arbitrarily delimited symbols to be a comment, and set up its unique formatting. The command

\lstset{morecomment=[s][\color{blue}]{@}{\ }}


means that any sequence of symbols ([s]) delimited by @ and space, will be typeset in blue.

\documentclass{article}
\usepackage{listings,xcolor}
\pagestyle{empty}
\lstset{language=bash}
\lstset{morecomment=[s][\color{blue}]{@}{\ }}
\begin{document}
\begin{lstlisting}
# This is an example
@Blueword # This will be done properly
for x in *~; do
echo $x; done # This too @Blueword x for x in *~; do echo$x;
done
# And this one
@Blueword
for x in *~; do
echo \$x;
done
\end{lstlisting}
\end{document}


-
Thanks for {\ }. That's what I've been looking for... –  projetmbc Apr 11 '12 at 17:15
I've updated my question because there are some drawbacks... –  projetmbc Apr 11 '12 at 17:31
Unfortunately listings does not accept multiletter delimiters (yet?), so in your example you need to write @decorator (arg). By the way, I know at least one company, where a space between function name and opening bracket is required by the coding style. –  Boris Apr 11 '12 at 17:40