Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 `?

share|improve this question
    
Welcome to TeX.SE. –  Peter Grill Nov 21 '12 at 20:17
    
thank you...... –  Rasmus Nov 22 '12 at 14:22

1 Answer 1

up vote 3 down vote accepted

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:

enter image description here

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}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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