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'm trying to create a listings language definition for ARM assembly and many of the instructions have prefixes/suffixes (i.e. BGT, BLE, BNE, BEQ branch instructions).

Is there a way to define B with any suffix as a keyword? Or am I stuck adding every combination of prefix/suffix/instruction in my list of keywords?

share|improve this question
1  
Related Question: Listings: text highlighting based on prefix. –  Peter Grill Jan 13 at 19:04
add comment

2 Answers

up vote 9 down vote accepted

You can use the keywordsprefix=<prefix> to specify that anything beginning with the <prefix> is considered a a keyword. The MWE below highlights any word beginning with B in blue, but leaves other text alone:

enter image description here

However you should note the following limitations form the listings documentation:

  1. The prefix is always case sensitive.

  2. Only one prefix can be defined at a time.

  3. If used standalone outside a language definition, the key might work only after selecting a nonempty language (and switching back to the empty language if necessary).

  4. The key does not respect the value of classoffset and has no optional class argument.

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

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

\begin{document}
\begin{lstlisting}
    ABC BGT DEF
    BLE XYZ MWS
    BNE DNW QES
    ABN BEQ MWE
\end{lstlisting}
\end{document}
share|improve this answer
    
Thanks, that's just what I'm looking for! –  Phil Lamb Feb 24 '12 at 4:06
add comment

I was also looking for a language definition for the ARM assembler and I came up with building the (huge) list of all keywords.

The result, including the python script to generate the keywords is on github.

share|improve this answer
1  
Welcome to TeX.SX. –  Claudio Fiandrino Oct 27 '13 at 13:19
add comment

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.