%%
%% from comp.text.tex
%%
\listfiles
\documentclass{jarticle}
\usepackage{fancyvrb,color}

\newif\ifhilite
\def\hilitelines(#1){%
  \def\FancyVerbFormatLine##1{%
    \def\fancylineinput{##1}%
    \hilitefalse
    \splitfirst #1,\relax,%
    \ifhilite\else
      \fancylineinput
    \fi}}

\def\splitfirst#1,{%
  \ifx\relax#1\empty\else
    \hiliteline{#1}{\fancylineinput}\expandafter\splitfirst
  \fi}

\def\hiliteline#1#2{%
    \ifhilite\else
      \ifnum\value{FancyVerbLine} = #1
        \colourcmd{#2}\hilitetrue
      \fi
    \fi}

\begin{document}

To highlight certain lines of verbatim text, use the
\verb|\hilitelines(x,y,...)| command, with \verb|x,y,...| any set of
line numbers corresponding to lines to be coloured:
\def\colourcmd{\textcolor{blue}}
\hilitelines(5,2,3)
\begin{Verbatim}
Some verbatim
text in \TeX\ with
\usepackage{fancyvrb}
for some
testing trying to
get some colour!
\end{Verbatim}

Redefine \verb|\colourcmd| to change the highlighting from text colour
to background colour, say:
\def\colourcmd{\colorbox{yellow}}
\hilitelines(4,1,6)
\begin{Verbatim}
Some verbatim
text in \TeX\ with
\usepackage{fancyvrb}
for some
testing trying to
get some colour!
\end{Verbatim}

\def\colourcmd{\textcolor{blue}}
\hilitelines(5,2,3)
\begin{Verbatim}
Some verbatim
text in \TeX\ with
\usepackage{fancyvrb}
for some
testing trying to
get some colour!
\end{Verbatim}

\def\colourcmd{\colorbox{yellow}}
\hilitelines(4,1,6)
\begin{Verbatim}
Some verbatim
text in \TeX\ with
\usepackage{fancyvrb}
for some
testing trying to
get some colour!
\end{Verbatim}

\end{document}
