Bollchen.de
Burkart Lingner

LaTeX listings: Emphasize the backslash, too

  • April 24, 2011 18:02

It always striked me as odd that the listings package doesn’t include the leading backslash of (La)TeX commands when emphasizing them. Thankfully you can change that behavior by i.e. setting \lstset{\texcsstyle=*\bfseries} (note the asterisk). Unfortunately this cuts the connection between the styling of LaTeX commands and that defined as keywordstyle. In order to have LaTeX commands and the leading backslash styled just like keywords in any other language, use

\lstset{texcsstyle=*\lst@keywordstyle}

in the document’s preamble. The actual keyword style is changed via

\lstset{keywordstyle=...}

Good-looking line breaks with the listings package

  • April 24, 2011 17:48

If you want to typeset source code in LaTeX you’ll probably end up using the listings package. The output looks good and you have quite a few options to customize it to your taste. Some of those options deal with how long lines are wrapped. Personally, I like them to look this way: