Highlighting in the LaTeX Verbatim environment.

This entry was posted by on Wednesday, 20 April, 2011 at

You want to show some output (say an event trace) and want to highlight certain passages. LaTeX’s verbatim environment is a nice and quick way to format this, but you cannot do any fancy tricks. The lstlistings package comes with syntax highlighting for various programming languages. But it’s not code we’re showing, its basically raw data where we want to highlight some important section. How’d we do that?
First, drop verbatim and use Verbatim. You’ll need these packages:

\usepackage{amssymb}
\usepackage{fancyvrb}
\usepackage{color}

Then we define a "\verbbf" command:

\newcommand\verbbf[1]{\textcolor[rgb]{0,0,1}{\textbf{$\blacksquare$ #1}}}

It's quite powerful, you can add any kind of markup (I color the text slightly blue, make it bold and add amssymb's blacksquare in front.

Then use it like this:


\begin{Verbatim}[commandchars=\\\{\}]
64787 E # 7212 t 5.522991476131 m 20 ce 7211 msg 10
64788 - 5.522991476131 handleLowerControl contention
\verbbf{64789 - 5.522991476131 suspend contention: began 5.522950381231, would end 5.523126381231, ifs 0.000176, quiet time 0.0000410949}
64790 - suspended during D/E/A IFS (no backoff)
64791 - suspended backoff timer, remaining backoff time: 0
\end{Verbatim}

Note how line 64789 stands out. Simple as that.

Comparison:

Comparison of the verbatim and Verbatim environments

References:
http://scott.sherrillmix.com/blog/category/programmer/latex/


Leave a Reply