# Command for a question in Beamer

I like to include a "feedback question" at the end of each slide, to check that my students are following me. For that, I include code such as:

\begin{overlayarea}{\textwidth}{1cm}
\only<5>{\hfill\beamerbutton{How do we get last expression?}}
\only<6>{\hfill\begin{beamercolorbox}[rounded=true,right]{solucion}
Using a Taylor series expansion
$e^t = 1 + t + t^2/2! + t^3/3! + \ldots$
\end{beamercolorbox}}
\end{overlayarea}


The problem with this is that I have to set manually the level of the overlay; for instance, the question above comes from a slide with four previous items.

I would like to have a new command to simplify this. I have tried,

\newcommand{\pregunta}[4]{%
\begin{overlayarea}{\textwidth}{1cm}
\only<#1>{{\hfill\beamerbutton} #3 }}}
\only<#2>{{\hfill
\begin{beamercolorbox}[rounded=true,right]{solucion}
#4
\end{beamercolorbox}}}
\end{overlayarea}}


but it just doesn't work. Ideally, I would like a command that frees me from having to pass as arguments the two overlay levels (#1, #2), so it works at the end of a slide irrespective of how many items it has (and continues to work if an item is added or removed!).

-
Why don't you use a new slide after the previous one? –  Sigur Jan 26 '13 at 15:12
Because I want my students to have in front of them the current slide when I ask them the feedback question. –  F. Tusell Jan 26 '13 at 15:21

Have a look at incremental overlay specifications (section 9.6.4 of the beamer manual). You could do something like this:

\documentclass{beamer}

\newcommand{\pregunta}[2]{%
\begin{overlayarea}{\textwidth}{1cm}
\only<+>{\hfill\beamerbutton{#1}}%
\only<+>{\hfill\begin{beamercolorbox}[rounded=true,right]{solucion}#2
\end{beamercolorbox}}%
\end{overlayarea}}

\begin{document}
\begin{frame}{original implementation}
\begin{enumerate}
\item<1-> foo
\item<2-> bar
\item<3-> baz
\item<4-> buzz
\end{enumerate}
\begin{overlayarea}{\textwidth}{1cm}
\only<5>{\hfill\beamerbutton{How do we get last expression?}}
\only<6>{\hfill\begin{beamercolorbox}[rounded=true,right]{solucion}
Using a Taylor series expansion
$e^t = 1 + t + t^2/2! + t^3/3! + \ldots$
\end{beamercolorbox}}
\end{overlayarea}
\end{frame}

\begin{frame}{macro implementation}
\begin{enumerate}[<+->]
\item foo
\item bar
\item baz
\item buzz
\end{enumerate}
\pregunta{How do we get last expression?}
{Using a Taylor series expansion $e^t = 1 + t + t^2/2! + t^3/3! + \ldots$}
\end{frame}

\end{document}


Then if you use the same style of overlay specification in your slides this will automatically add two more in sequence.

If it were me I would create two overlay-specification-aware environments so I could have something a bit more semantic in the markup (sorry, this doesn't exactly work right now. I'll have to come back to it later):

\newenvironment<>{pregunta}[1]{%
\begin{onlyenv}#1\hfill\beamerbutton}{%
\end{onlyenv}
}
\newenvironment<>{solucion}[1]{%
\begin{beamercolorbox}#1[rounded=true,right]{solucion}}{%
\end{beamercolorbox}}

\begin{overlayarea}{\textwidth}{1cm}
\begin{pregunta}<+>
How do we get last expression?
\end{pregunta}
\begin{solucion}<+>
Using a Taylor series expansion $e^t = 1 + t + t^2/2! + t^3/3! + \ldots$
\end{solucion}
\end{overlayarea}


Then you can also use beamer's theme mechanism to style them consistently.

I had thought that you could still hard-code your slide numbers by using the beamerpauses counter. But it seems that this counter is only used when incremental overlay specifcations are.

-
Thank you very much. Using auto-increment (<+->) works for me as you say. I wish it could also be used when I code overlays manually, which sometimes I need to do for more control. But your solution is good enough for most of my uses. –  F. Tusell Jan 26 '13 at 18:32
@F.Tusell: I'm glad it works for you. You can do a lot with the incremental overlays, including with offsets so you never have to hard-code any numbers. If I can get my overlay-specification-aware version working you could use either/or. –  Matthew Leingang Jan 26 '13 at 19:49