Question

I use the listings package to insert source code. I would like to print all keywords uppercase in the output, regardless of the case in the input.

The manual states that

keywordstyle=[number][*]style

produces just what I want. However the following (almost) minimal example does not work. if I set keywordstyle to "[1][]{\bfseries}" I end up with "[]" in front of every keyword and "[*]{\bfseries}" gives me an asterisk in the start of the document.

I also tried "\MakeUppercase" and "{\MakeUppercase}" for keywordstyle which resulted in several errors, the first being:

! Incomplete \iffalse; all text was ignored after line 11

Minimal example:

\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{KA_assembler}
{morekeywords={add,and,or,xor},
keywordstyle=[1][*]{\bfseries},
sensitive=false,
}
\lstset{language=KA_assembler}
\begin{document}
\begin{lstlisting}
and %r1, %r2
xor %r2, %r3
and %r4, %r5
\end{lstlisting}
\end{document}

I use Miktex for compilation of the tex files. So how do I force uppercase for Keywords?

Was it helpful?

Solution

In the manual, the brackets around the * look a bit different then the brackets around number. The reason is that the brackets around * are not meant to be used in the latex code, they just indicate that the presence of the * is optional. So try

keywordstyle=[1]*\bfseries

or

keywordstyle=*\bfseries

- it worked for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top