Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coloring the verbatim like environment?

Tags:

latex

This is a screen capture from Pragmatic Bookshelf book.

http://img13.imageshack.us/img13/3168/screenshot20100717at123.png

It looks like that the verbatim environment with the coloring, but I'm not sure.

How can one can use color for verbatim like environment as is shown?

Using line by line method would be a solution, but I expect a better way to go.

{\color{red}\begin{verbatim}
line 1
     line 2
\end{verbatim} }
\color{blue}{\begin{verbatim}
line 3
     line 4
\end{verbatim}}
like image 886
prosseek Avatar asked Jul 17 '10 19:07

prosseek


3 Answers

An example using fancyvbr package

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{color}
\usepackage[utf8]{inputenc}
\usepackage{fancyvrb}
\usepackage[usenames,dvipsnames]{xcolor}

\fvset{frame=single,framesep=1mm,fontfamily=courier,fontsize=\scriptsize,numbers=left,framerule=.3mm,numbersep=1mm,commandchars=\\\{\}}

\begin{document}
   \begin{Verbatim}[label={My orange command sample output}]
# \textcolor{Orange}{My orange command}
My black output
that it can be
many lines long
but this specific \textbf{\textcolor{OliveGreen}{word}}
and the following 2
\textbf{\textcolor{red}{lines are important so they}}
\textbf{\textcolor{red}{need to be highlighted and bold}}
   \end{Verbatim}
\end{document}

Sample output of this code

like image 155
Vangelis Tasoulas Avatar answered Oct 26 '22 13:10

Vangelis Tasoulas


You can use the fancyvrb package. It includes options for colouring, so you can just use multiple Verbatim environment blocks.

like image 42
igorw Avatar answered Oct 26 '22 14:10

igorw


You can use the listings package also:

\lstinputlisting[language=Ruby]{source_filename.rb}

Or

\begin{lstlisting}
\end{lstlisting}
like image 3
SiggyF Avatar answered Oct 26 '22 14:10

SiggyF