[Tex/LaTex] How to add custom beamer actions that change an argument

beameroverlays

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?

Best Answer

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.)