# Animation effect of text being deleted with Beamer?

I want a slide I'm making to have text that begins to be written out, and is then un-written, character by character. So,

• First the slide says "Hello Alice"
• Then the "Alice" gets deleted gradually
• The slide ends up saying "Hello Bob"

I can sort-of do this with Beamer already, using \only for the different versions of the letter, or just for a whole chunk, but I was hoping there's a less cumbersome way to achieve this.

Is this possible?

I would also want to make it appear a bit more like a typing, erasure and re-typing/over-typing, but that visual effect is more of an icing on the cake and not at all critical.

• Not what you are asking for, but maybe slide transitions could be used to exchange the two words:  \transfade<1-2>[duration=1] Hello \alt<+(1)->{Bob}{Alice} Mar 14 '18 at 15:56

My original answer shows how such things can be done in general, and this update is tailor-made for this specific task (hello identical, and Alice has 5 letters while Bob has 3). And there are, in general, 3 quantities: \Y for the overlay specification in only, \X for how much of Alice should be kept (counting from left) and \Z for how much of Bob should be displayed (counting from right). \pgftruncatemacro is used in the original answer because otherwise the numbers will be 1.0, 2.0 etc. Here I use the evaluate option instead. Of course, if you wish to use this trick very often, you could put it into a macro.

\documentclass{beamer}
\usepackage{xstring,pgffor}
\begin{document}
\begin{frame}
\frametitle{Alice vs.\ Bob}
\foreach [count=\Y,evaluate={\Z=int(\Y-1)}] \X in {5,...,2}
{
\only<\Y>{
Hello \StrLeft{Alice}{\X}\StrRight{ Bob }{\Z}}
\pause
}
Hello Bob
\end{frame}
\end{document}


\documentclass{beamer}
\usepackage{xstring,pgffor}
\begin{document}
\begin{frame}
\frametitle{Alice vs.\ Bob}
\foreach [count=\Y] \X in {11,...,1}
{
\only<\Y>{\pgfmathtruncatemacro{\Z}{\Y-1}
\StrLeft{Hello Alice}{\X}\StrRight{Hello Bob}{\Z}}
\pause
}
\end{frame}
\end{document}

• Why the \mgfmathtruncatemacro and the three different variables \X \Y and \Z? Mar 14 '18 at 16:23