# How to I emphazise all words beginning with  in an lstlisting

I use a preprocesser to process some code before my verilog compiler.
All preprocesser words start with the  character

Example:

pp_if


unfortunately its possible to define your own preprocessor words. The only thing that is known is that the word starts with .

How can I highlight any word starting with ?

-
–  Peter Grill Nov 21 '12 at 20:17
thank you...... –  Rasmus Nov 22 '12 at 14:22

You can adapt the solution from Listings language definition keyword suffixes and use the keywordsprefix=<prefix> to specify that anything beginning with tick is considered a keyword:

## Notes:

• To obtain the a more reasonable display of leading tick, I added upquote=true which requires the textcomp package. There may be a better way to handle the issue of displaying the .
• There are limitations of using keywordsprefix=<prefix> which are noted in Listings language definition keyword suffixes.

## Code:

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

\lstset{%
backgroundcolor=\color{yellow!20},%
basicstyle=\small\ttfamily,%
numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt,%
keywordstyle=\color{blue}\bfseries,
language=Java,
keywordsprefix=,
upquote=true,
}%

\begin{document}
\begin{lstlisting}
pp_if pp rr
pp_if mm zz
xx MM PP
abc def ghi
\end{lstlisting}
\end{document}

-
I will try this thank you :) –  Rasmus Nov 22 '12 at 11:47
Ok know it gets a bit tricky. i want to do the words starting with  a different color than the other keywords. I tried with the emph, but then i can't do the prefix stuff.. any suggestions? –  Rasmus Nov 22 '12 at 13:55
@Rasmus: Since it is called keywordprefix (and with the highlighting of restrictions as pointed out in Listings language definition keyword suffixes) this may not be easily doable, without much hackery (might be useful as a separate question). One solution might be to copy the code for keywordprefix and define emphstyleprefix` and try to adapt that.. –  Peter Grill Nov 22 '12 at 19:06
@Rasmus: Also, if this answered your question you should consider accepting it: How do you accept an answer? –  Peter Grill Nov 22 '12 at 19:06
thank you i will do that :) –  Rasmus Nov 23 '12 at 11:32