Tuesday, November 1, 2011

LaTeX: Verbatim code on a box with background

The code that follows defines the
  verbcode environment, which is handy to include in a LaTeX document a verbatim code box with a fancy colored background as seen shown in the figure. This code snip produces the figure shown.

\documentclass[11pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% verbatim boxed text \usepackage{fancyvrb,fancybox,calc} \usepackage[svgnames]{xcolor} \newenvironment{verbcode}{\VerbatimEnvironment% \noindent % {\columnwidth-\leftmargin-\rightmargin-2\fboxsep-2\fboxrule-4pt} \begin{Sbox} \begin{minipage}{\linewidth-2\fboxsep-2\fboxrule-4pt} \begin{Verbatim} }{% \end{Verbatim} \end{minipage} \end{Sbox} \fcolorbox{black}{LightGray}{\TheSbox} }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} Here is some some code \begin{verbcode} $ run_me.sh param1 \ + ]0 \end{verbcode} \end{document}

Sources:
http://tex.stackexchange.com/questions/18322/using-fancyvrb-verbatim-environment-from-within-newenvironment
http://groups.google.com/group/latexusersgroup/browse_thread/thread/c8c2e5dd1e9ff5cf
LaTeX code highlighted using: http://www.hilite.me/

2 comments: