Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wanted to do something similar like here:

Improving typewriter animation

But using the animate package. I managed to get a very poor solution:

\documentclass{article}
\usepackage[latin1]{inputenc}

\usepackage{animate}
\usepackage{amsmath}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{animateinline}

\begin{document}

\begin{center}
\fboxsep1mm
    \begin{animateinline}[autoplay,loop]{2}
    % one frame per second
    $\phantom{\text{Alles Gute zum Geburtstag!}}$
    \newframe   
    $\text{Alles}\phantom{\text{ Gute zum Geburtstag!}}$
    \newframe       
    $\text{Alles Gute}\phantom{\text{ zum Geburtstag!}}$
    \newframe       
    $\text{Alles Gute zum}\phantom{\text{ Geburtstag!}}$
    \newframe   
    $\text{Alles Gute zum Geburtstag}\phantom{\text{!}}$
    \newframe   
    $\text{Alles Gute zum Geburtstag!}\phantom{\text{}}$                    
    \end{animateinline}
\end{center}

\end{document}

The \phantom is in my experience needed to reserve in all frames the same space. Otherwise the text gets distorted.

Here is the result:

http://www.bipede.de/Downloads/HB.pdf

Has someone an idea how to get the very cool solution in

Improving typewriter animation

to work here?

By the way, Alles Gute zum Geburtstag means Happy Birthday in German.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Character for character

The usage of the xstring macros is taken from the linked question.

The width of the text (in \Huge style) is saved to \mytextwidth.
As \StrLen counts from 0 to, in this case, 27, \multiframe needs to animate 28 frames, which is why \mylen+1 is calculated and saved to \frames.

This example uses the \multiframe macro because we can use variables (the other question used PGF's \foreach for this) and don't need to type every frame individually.

The \vphantom is needed because we start with no text (\icounter=0) and we need vertical height for. If you want to start with A use icounter=1+1 and re-replace \frames with \mylen in the \multiframe command.

\makebox makes everytime a box of the full text's width so that animate doesn't stretch the text. (We could have used also \StrRight, but this needs less calculation.)

Code (char for char)

\documentclass{article}
\usepackage[latin1]{inputenc}

\usepackage{animate}
\usepackage{calc}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{animateinline}

\usepackage{xstring}

\def\mytext{Alles Gute zum Geburtstag!}
\StrLen{\mytext}[\mylen]
\newlength{\mytextwidth}
\setlength{\mytextwidth}{\widthof{\Huge\mytext}}
\def\frames{\number\numexpr\mylen+1\relax} % \frames = \mylen + 1

\begin{document}


\begin{center}
\begin{animateinline}[autoplay,loop]{2}
  \multiframe{\frames}{icounter=0+1}{
    \makebox[\mytextwidth][l]{\Huge\vphantom{\mytext}\StrLeft{\mytext}{\icounter}}
  }
\end{animateinline}
\end{center}
\end{document}

Looks a lot like … (a.k.a. Output)

enter image description here

Word for word

Code

\documentclass{article}
\usepackage[latin1]{inputenc}

\usepackage{animate}
\usepackage{calc}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{animateinline}

\usepackage{xstring}

\def\mytext{Alles Gute zum Geburtstag!}
\StrCount{\mytext}{ }[\countSpaces]
\newlength{\mytextwidth}
\setlength{\mytextwidth}{\widthof{\Huge\mytext}}
\def\frames{\number\numexpr\countSpaces+2\relax} % \frames = \countSpaces + 2

\begin{document}
\begin{center}
\begin{animateinline}[autoplay,loop]{2}
  \multiframe{\frames}{icounter=0+1,icounterr=1+1}{%
    \makebox[\mytextwidth][l]{%
      \Huge\vphantom{\mytext}%
      \ifnum\icounter=0\relax\else
        \ifnum\icounterr=\frames\relax\mytext\else%
          \StrBefore[\icounter]{\mytext}{ }%
        \fi
      \fi
    }%
  }
\end{animateinline}
\end{center}
\end{document}
share|improve this answer
    
Awesome. Thank you very much. I was at work, therefore the late reply. –  Manuel Kuehner Nov 8 '12 at 18:53
    
Is it possible show the last frame (complete message) of the animation if the animation fails (either because the viewer --like Evince-- does not show the animation or because something is disabled in Acrobat)? –  alfC Jun 12 at 8:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.