Activar automáticamente comandos de formato agrupados en superposiciones

Activar automáticamente comandos de formato agrupados en superposiciones

Me gustaría obtener un resultado idéntico al siguiente:

\documentclass{beamer}
\begin{document}

\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \alt<5>{{\color{blue}on average}}{on average} produce
five men and five women, but... \uncover<+->{ any given trial is likely to over-represent one sex and underrepresent
the other.}
\item Analogy: if you flip a fair coin 10 times, \alt<5>{{\color{blue}on average}}{on average} you'll get 5
heads and 5 tails, but... \uncover<+->{ sometimes we might get 7 heads and 3 tails, and other times 8 tails
and 2 heads.}
\item What does ``\alt<5>{{\color{blue}on average}}{on average}'' mean above?
\item It means that if we were to take a lot of samples.... blah blah.
\end{itemize}
\end{frame}

\end{document}

Sin embargo, en lugar de \alt<5>{{\color{blue}on average}}{on average}, quiero poner perezosamente \groupA{on average}para las dos primeras instancias de "en promedio", y en la tercera y última algo como \revealGroupA{on average}. Es decir, quiero escribir el siguiente código pero lograr el mismo resultado que el anterior:

\documentclass{beamer}
\begin{document}

\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \groupA{on average} produce
five men and five women, but... \uncover<+->{ any given trial is likely to over-represent one sex and underrepresent
the other.}
\item Analogy: if you flip a fair coin 10 times, \groupA{on average} you'll get 5
heads and 5 tails, but... \uncover<+->{ sometimes we might get 7 heads and 3 tails, and other times 8 tails
and 2 heads.}
\item What does ``\revealGroupA{on average}'' mean above?
\item It means that if we were to take a lot of samples.... blah blah.
\end{itemize}
\end{frame}

\end{document}

Algunas notas:

  • En el ejemplo, el argumento ("en promedio") es siempre el mismo, pero en otros casos de uso ese no es el caso.

  • También hago esto mucho en matemáticas, por lo que sería bueno que el comando funcionara en matemáticas y fuera de ellas.

  • Probablemente usaría este mecanismo en varios fotogramas diferentes del mismo archivo.

  • No estoy seguro de si es relevante, pero planeo ampliar la respuesta para crear también un \groupBcomando, que esencialmente haría lo mismo pero usaría un color diferente. La razón de esto es que es posible que desee utilizar ambos \groupAy \groupBen el mismo marco.

Respuesta1

Puede usar el totcountpaquete para almacenar el número de superposición en el que se revelará su grupo entre compilaciones (no reutilice el mismo grupo en marcos diferentes):

\documentclass{beamer}


\makeatletter
\newcommand*{\slideinframe}{\beamer@slideinframe}
\makeatother

\usepackage{totcount}


\setbeamercolor{alerted text}{fg=blue}

\newcounter{overlaygroupA}
\setcounter{overlaygroupA}{0}

\newcommand{\revealGroupA}[1]{%
  \only<.>{\setcounter{overlaygroupA}{\slideinframe}}%
  \alert<.>{#1}%
}

\newcommand{\groupA}[1]{%
  \alert<\totvalue{overlaygroupA}>{#1}%
}

\regtotcounter{overlaygroupA}

\begin{document}

\begin{frame}[<+->]{Sampling}
\begin{itemize}
\item A random sample of ten people from the US will \groupA{on average} produce
five men and five women, but... \uncover<+->{ any given trial is likely to over-represent one sex and underrepresent
the other.}
\item Analogy: if you flip a fair coin 10 times, \groupA{on average} you'll get 5
heads and 5 tails, but... \uncover<+->{ sometimes we might get 7 heads and 3 tails, and other times 8 tails
and 2 heads.}
\item What does ``\revealGroupA{on average}'' mean above?
\item It means that if we were to take a lot of samples.... blah blah.
\end{itemize}

\end{frame}

\end{document}

ingrese la descripción de la imagen aquí

información relacionada