Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to use Beamer's \alert<x>{...} command inside of a Verbatim environment (from the fancyvrb package) to highlight the text. I've found that when the \alert command is inside the Verbatim, it just highlights the text, but doesn't do any overlays.

Can I use the overlay feature of \alert inside a Verbatim environment?

Note: I don't want to use a semiverbatim environment because I want to put a frame around the text. A minimal working example is copied below. It does not do what I'd like it to.

\documentclass{beamer}
\usepackage{fancyvrb}

\begin{document}

\begin{frame}[fragile]{Testing}

\begin{Verbatim}[commandchars=\\\{\},fontsize=\scriptsize,frame=single]
1.423930+0 8.164981+5 1.257190+02834 3  2  545
1.900300-1 \alert<2>{8.184120+5 3.506000-7}2834 3  2  546
2.307450-2 8.192910+5 2.396970-12834 3  2  547
\end{Verbatim}
\end{frame}

\end{document}

enter image description here

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The following may be a viable work-around:

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\let\Tiny\tiny% http://tex.stackexchange.com/q/58087/5764
\usepackage{fancyvrb}% http://ctan.org/pkg/fancyvrb

\let\oldalert\alert
\renewcommand{\alert}[2][]{%
  \if\relax\detokenize{#1}\relax% http://tex.stackexchange.com/q/53068/5764
    \oldalert{#2}% Default overlay
  \else
    \oldalert<#1>{#2}% Specific overlay
  \fi}

\begin{document}
\begin{frame}[fragile]{Testing}

Slide \alt<1>{1}{2}\ldots

\begin{Verbatim}[commandchars=\\\{\},fontsize=\scriptsize,frame=single]
1.423930+0 8.164981+5 1.257190+02834 3  2  545
1.900300-1 \alert[2]{8.184120+5 3.506000-7}2834 3  2  546
2.307450-2 8.192910+5 2.396970-12834 3  2  547
\end{Verbatim}
\end{frame}

\end{document}

The \alert macro is first stored in \oldalert in order to preserve the overlay specification interface (requiring the use of <.>). Then it is redefined to capture an optional (overlay) and mandatory (stuff to alert) argument in a more traditional way. That is, the interface \alert<.>{..} is updated to reflect \alert[.]{..} which fancyvrb seems to cope with better.

A simpler definition may be to only use

\let\oldalert\alert
\renewcommand{\alert}[2]{\oldalert<#1>{#2}}

which assumes you'll always specify an overlay and renews the interface to \alert{.}{..}.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.