LaTeX semiverbatim and fancyvrb

latex

I'm creating a presentation using the beamer LaTex package. Beamer
comes with an environment called "semiverbatim" which is like
"verbatim", but allows you to place commands inside the environment.
This is useful in beamer to control how the overlays of a frame
unfold. For example:

\begin{frame}[fragile, shrink]
  \frametitle{Some Code Sample}
\begin{semiverbatim}
private String foobar() \{
    String s = "val"
    \alert<2->{s = null};}
    return s;
\}
\end{semiverbatim}
\end{frame}

This will cause the third line to appear red in the second stage of
the frame transition.

This is all good and fine, however, the "semiverbatim" environment,
much like the "verbatim" environment, is pretty limited. I would like
to use the "Verbatim" environment from the fancyvrb package.

Is there anyway to use "Verbatim" in the same way "semiverbatim" is
used?

Best Answer

I'm not having much luck, I'm afraid. I can get the \alert to work okay, but only without an overlay specification:

\documentclass{beamer}
\usepackage{fancyvrb}
\begin{document}
\begin{frame}[fragile]
\frametitle{Some Code Sample}
\begin{Verbatim}[commandchars={\\[]}]
private String foobar() {
    String s = "val"
    \alert[s = null];}
    return s;
}
\end{Verbatim}
\end{frame}
\end{document}

When you try \alert<2-> it breaks, and changing catcodes of < and > doesn't seem to help.