# Letter by letter uncovering animation effect?

I need an appearing effect for text like the one (in javascript) here http://jsfiddle.net/VZvK7/.

However I don't know how to insert js code into LaTeX (apart from using the AcroTeX Bundle) and that would also force me to use Acrobat Reader, so I'd like to implement a similar effect in Beamer. Is it possible?

(of course I would love to see alternative approaches to this)

The basic idea is to put each letter into a single slide.

\documentclass{beamer}
\usepackage{pgffor}
\usepackage{ragged2e}   %for justification

\newcommand{\comma}{,}

\newcommand{\myduration}[1]{%
\foreach \l in {#1}{%
\transduration<\l>{.05}%
}%
}

\newcommand{\anitext}[2]{%
\myduration{#1}%
\foreach \i in {#2}{%
\temporal<+>{}{\Large\bfseries \vphantom{Mpgjy}\i}{\vphantom{Mpgjy}\i}%        %the phantom removes the bumping
}%
}

\begin{document}
\begin{frame}
\justifying
\pause

\anitext{2,...,122}{%
L,o,r,e,m,\space,i,p,s,u,m,\space,d,o,l,o,r,\space,s,i,t,\space,a,m,e,t\comma,\space,c,o,n,s,e,c,t,e,t,u,r,\space,a,d,i,p,i,s,c,i,n,g,\space,e,l,i,t\comma,\space,s,e,d,\space,d,o,\space,e,i,u,s,m,o,d,\space,t,e,m,p,o,r,\space,i,n,c,i,d,i,d,u,n,t,\space,u,t,\space,l,a,b,o,r,e,\space,e,t,\space,d,o,l,o,r,e,\space,m,a,g,n,a,\space,a,l,i,q,u,a.
}
\end{frame}
\end{document}


What I used:

1. \comma: a macro for having commas in text without messing up the loop
2. \myduration: a macro that sets a \transduration effect of .05 seconds. For each letter.
3. \anitext: a macro for setting the animation effect using Beamer \temporal internally, in the example the text appears as bold and \Large and then goes back to normal.

Of course the text to be animated needs to be pre-processed so that each letter is followed by a comma. To do that I put the text to be animated into a separate file and used:

cat <finename> | fold -w1 | paste -sd+, -


Also, each space needs to be replaced by a \space macro (I did it via search&replace).

The first argument of the \anitext macro is equal to the number of characters in the original text (without the commas). It is also possible to add a comma after each couple of characterd (with fold -w2) but then the animation is less fluid.

In the MwE the animated text starts at slide number 2, so that the user can advance to slide number 2 when he wants to start the animation and then admire the fake animation :)

I used this also with longer text, up to 450 characters, and apart from the ridiculous number of slides of the resulting PDF, it works fine.

• Effects like this are easy to get with common presentation programs (which I wouldn't mention the name of). They are annoying, to say the least. Oct 4 '14 at 19:31
• @egreg I think I may have an idea which program you are referring to ;). Anyway, in general I agree (I wouldn't use this into some serious-professional-whatever presentation - if not for pissing off the public), but then, there are more use cases in heaven and earth than are dreamt in your philosophy, as the Poet famously said :) Oct 4 '14 at 19:38
• Is there some way to do this more "automatic" using luatex? Jun 18 '19 at 7:02