开发者

Latex listings-package format option for uppercase keywords

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 t开发者_如何学Cext 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜