# How do I add custom beamer actions that change an argument?

The beamer manual says:

You can easily add your own actions: An action specification like ⟨action⟩@⟨slide numbers⟩ simply inserts an environment called ⟨actionenv around the \item or parameter of \action with <slide numbers> as overlay specification. Thus, by defining a new overlay-specification-aware environment named ⟨my action nameenv, you can add your own action:

\newenvironment{checkenv}{\only{\setbeamertemplate{itemize item}{X}}}{}


You can then write

\item<beamer:check@2> Text.


This will change the itemization symbol before Text. to X on slide 2 in beamer mode. The definition of checkenv used the fact that \only also accepts an overlay-specification given after its argument.

I'd like an action like \alert which instead colors its input gray. So I tried:

\documentclass{beamer}

\newenvironment<>{grayenv}{%
\color#1{gray}}{}

\begin{document}

\begin{frame}
Text is \begin{grayenv}<2-> grayed out\end{grayenv}.
\end{frame}

\begin{frame}
Who's \action<alert@+| gray@+(1)>{gray} now? \action<+(1)->{And now?}
\end{frame}

\begin{frame}
Who's \action<alert@+| grayenv@+(1)>{gray} now? \action<+(1)->{And now?}
\end{frame}
\end{document}


The first frame has the expected output: "grayed out" is grayed out on slide 2. The second frame has "Who's ¡all:¿gray now?" (bold is red), followed by no coloring on the next two slides. The third frame has "gray now?" (not "gray" as desired) grayed out on slide 2.

The only working examples of custom action I have seen are written as checkenv is: not as an overlay-aware environment, but a regular environment that ends its begin code with an \only{...} (see also this longer example).

Is there anyway to pass the overlay specification to the custom environment?

-

It appears to me Till got confused: your third example shouldn't work at all if \action wrapped its argument in the actionenv, not passing it as an argument to actioncommand.

Using

\newcommand<>\gray[1]{%
\textcolor#2{gray}{#1}%
}


appears to work. (FYI: the ?all:2! that you observe was the < all:2 > specification that was not being taken up because no command \gray existed to parse it. (The inverted ? and ! happen to sit in the spaces for > and < if you don't use the T1 fontencoding. Even more tangentially, if you ever see ?From in a scientific paper and have to laugh, you know enough about TeX and RFC822 to qualify as a hopeless geek.)

-
Thanks, I'll give this a try. I knew that ¿all:2! was beamer not evaluating an overlay specification, but I wasn't sure how to fix it. And yes, I've seen "¿From" in papers and chuckled geekily to myself. (To share the joke: it means one author emailed another author TeX code and the second author copied-and-pasted into the tex file without much proofreading.) –  Matthew Leingang Dec 6 '10 at 19:49
Yes, it does appear to work. Thanks! I don't know what the env thing was about then. –  Matthew Leingang Dec 7 '10 at 1:21
@MatthewLeingang I ran into the same problem, and Ulrich's suggestion worked. Perhaps the Beamer powers that be could update the user guide in the next version? –  Henry DeYoung Jul 2 '12 at 20:14