Typewriter Animation with Math

A previous question inquires about animating some simple text, with an elegant solution that uses the animate package and the xstring package.

Is there a way to alter this code so that it works in math mode? For example, how can the following be animated to appear letter by letter?

Pythagorean theorem $a^2 + b^2 = c^2$


Also, is it possible to animate the following to appear character by character?

$$\text{Quadratic formula } x = \frac{-b \pm \sqrt{b^2 - 4 a c } }{ 2 a}$$


Animating either of these statements would be quite helpful.

Late edit:

Bonus for doing multiple lines in a single animation,

Pythagorean theorem $a^2 + b^2 = c^2$\par
This means $c = \sqrt{a^2 + c^2}$
$Cos \theta = \frac{c}{a}$


\documentclass{beamer}

\begin{document}

\Huge
\let~\pause
\frame{
P~y~t~h~a~g~o~r~e~a~n~\ $a^{~2}~+~b^{~2}~=~c^{~2}$
}

\end{document}


Another approach

\documentclass{beamer}

\begin{document}

\makeatletter
\def\BB{\pgfsys@begininvisible}
\def\EE{\pgfsys@endinvisible}
\makeatother

\begin{frame}
$$\text{Qua\only<1>{\BB}dra\only<2>{\BB}tic\only<3>{\BB} formula } x = \frac{-b \pm \sqrt{b^2 - 4 a c } }{ 2 a} \EE$$
\end{frame}

\begin{frame}
$$\text{Quadratic for\only<1>{\BB}mu\only<2>{\BB}la\only<3>{\BB} } x = \frac{-b \pm \sqrt{b^2 - 4 a c } }{ 2 a} \EE$$
\end{frame}

\begin{frame}
$$\text{Quadratic formula } x = \only<+>\BB\frac{-b\only<+>\BB\pm\only<+>\BB\sqrt{b^2 - 4 a c } }{ 2 a} \EE$$
\end{frame}

\begin{frame}
$$\text{Quadratic formula } x = \frac{-b \pm \sqrt{\only<+>\BB b^2\only<+>\BB- 4 a c\only<+>\BB} }{ 2 a} \EE$$
\end{frame}

\begin{frame}
$$\text{Quadratic formula } x = \frac{-b \pm \sqrt{b^2 - 4 a c } }{\only<+>\BB 2 a\only<+>\BB} \EE$$
\end{frame}

\begin{frame}
$$\BB \text{Quadratic \only<+>\EE formula \only<+>\EE} x = \only<+>\EE\frac{-b \pm \only<+>\EE\sqrt{b^2 - 4 a c } \only<+>\EE}{ 2 a}$$
\only<+>\EE
\end{frame}

\end{document}


• I meant to show two different approaches: \pause is no-brainer. Using \pgfsys gives you more control. (When to start and when to end). I'm pretty sure both lines can be done in both ways. Depending on how automatic it should be, maybe someone on this site can write a macro that insert \pause at every possible position. Edit the question to let people know what you want. Commented Jun 17, 2020 at 20:56
• What did you use to build these files? For me, MikTex pdfLaTex didn't work. Commented Jun 17, 2020 at 22:04
• I needed to follow tex.stackexchange.com/questions/133781/… Seems to work now. Commented Jun 18, 2020 at 1:21
• Hi. I am using texlive, it compiles the file nicely but the display is just the static text. Any ideas where I should look? Commented Sep 29, 2023 at 11:43
• @ahron Animation (in the context of beamer) usually means a sequence of static pages and you need to advance the pages yourself to create the effect of animation. Commented Sep 30, 2023 at 16:34