# Listings language definition keyword suffixes

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?

-
Related Question: Listings: text highlighting based on prefix. – Peter Grill Jan 13 '14 at 19:04

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:

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}

-
Thanks, that's just what I'm looking for! – Phil Lamb Feb 24 '12 at 4:06

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.

-
Welcome to TeX.SX. – Claudio Fiandrino Oct 27 '13 at 13:19
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5315662026405334, "perplexity": 4021.9530959664776}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-18/segments/1461860111612.51/warc/CC-MAIN-20160428161511-00216-ip-10-239-7-51.ec2.internal.warc.gz"}