summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/animate/doc/animate.tex
blob: 76305195f246580ec7478443a6c05418eace6e8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
% Copyright 2007--2008 Alexander Grahn
%
% This material is subject to the LaTeX Project Public License. See
%    http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html
% for the details of that license.
%
\documentclass[a4paper]{article}
\frenchspacing
\usepackage[UKenglish]{babel}
\usepackage{pst-3dplot}
\usepackage{fp}
\usepackage{animate}
\usepackage{intcalc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{textcomp}
\usepackage{lmodern}
\usepackage{mflogo}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{ifpdf}
\usepackage{parskip}

\makeatletter
\renewcommand{\fnum@figure}[1]{\figurename~\thefigure}
\makeatother

\ifpdf
  \makeatletter
  \@latex@error{Please use LaTeX to compile this documentation}
  \makeatother
\fi

\def\keywords{include portable PDF animation animated PDF animating embed animated graphics LaTeX pdfLaTeX PSTricks pgf TikZ LaTeX-picture MetaPost inline graphics vector graphics animated GIF LaTeX dvips ps2pdf JavaScript Adobe Reader}
\hypersetup{
  bookmarksnumbered,linktocpage,breaklinks,
  pdftitle={The animate Package},
  pdfsubject={Documentation},
  pdfauthor={Alexander Grahn},
  pdfkeywords={\keywords},
  citebordercolor={0 0 1},
  filebordercolor={0 0 1},
  linkbordercolor={0 0 1},
  menubordercolor={0 0 1},
  pagebordercolor={0 0 1},
  urlbordercolor={0 0 1},
%  pdfpagelayout=SinglePage
}

\begin{document}
\title{The {\sffamily animate} Package}
\author{Alexander Grahn \animategraphics[autoplay,loop,height=1.8ex]{8}{bye_}{0}{3}\protect\footnote{Animated GIF taken from \href{http://www.phpBB.com}{phpBB} forum software and burst into set of EPS files using \href{http://www.imagemagick.org}{ImageMagick} before embedding.}\\[1ex]\includegraphics[height=2.7ex]{mailto}}
\maketitle

\begin{abstract}
\raggedright

\noindent A LaTeX package for creating portable, JavaScript driven PDF animations from sets of vector graphics or rasterized image files or from inline graphics.
\vskip 0.2\baselineskip

\emph{Keywords}: \keywords
\end{abstract}

\tableofcontents

%\newpage
\section{Introduction}
This package provides an interface to create PDFs with animated content from sets of graphics or image files, from inline graphics, such as \LaTeX-picture, PSTricks or pgf/TikZ generated pictures, or just from typeset text. Unlike standard movie/video formats, which can be embedded, for example, using the \LaTeX{} package `movie15'~\cite{movie15}, package `animate' allows for animating vector graphics. The result is roughly similar to the SWF (Flash) format, although not as space-efficient.

Package `animate' supports the usual PDF making workflows, i.\,e. pdf\LaTeX{} and \LaTeX{} $\rightarrow$ \verb+dvips+ $\rightarrow$ \verb+ps2pdf+/Distiller.

The final PDF can be viewed in current Adobe Reader\textsuperscript{\scriptsize\textregistered}s on all supported platforms.

The `animate' package relies on Optional Content Groups (OCG), also known as PDF layers, which is a feature provided by the PDF-1.5 specification. Each frame of an animation is associated with an OCG that is hidden or made visible in a dynamic fashion by means of Adobe Reader's built-in JavaScript engine.

\section{Requirements}
\begin{trivlist}
\item $\varepsilon$-\TeX
\item pdf\TeX{}, version $\ge1.20$ for direct PDF output
\item Ghostscript, version $\ge8.31$ or Adobe Distiller for PS to PDF conversion
\item Adobe Reader, version $\ge6$, but not $8$
\end{trivlist}

\section{Installation}
The file `animate.sty' should be stored in a place where \LaTeX{} can find it.

\section{Using the package}
First of all, read Section~\ref{sect:bugs} on problems related to this package. Then, invoke the package by putting the line
\begin{verbatim}
\usepackage[<package options>]{animate}
\end{verbatim}
to the preamble of your document, i.\,e. somewhere between \verb+\documentclass+ and \verb+\begin{document}+.

`animate' honours the package options:
\begin{verbatim}
autoplay
autopause
autoresume
loop
palindrome
draft
final
controls
buttonsize=<size>
buttonbg=<colour>
buttonfg=<colour>
step
poster[=first | none | last]
\end{verbatim}
The same options (among others) are also available as command options and will be explained shortly. However, if used as package options they have global scope, taking effect on all animations in the document. In turn, command options locally override global settings.

If PDF is generated via DVI and Postscript by the command sequence \verb+latex+ $\rightarrow$ \verb+dvips+ $\rightarrow$ \verb+ps2pdf+, the `graphicx' package is required. \emph{Important:} The \verb+dvips+ option `\verb+-Ppdf+' should \emph{not} be set when converting the intermediate DVI into Postscript. If you cannot do without, put `\verb+-X 2400 -Y 2400+' \emph{after} `\verb+-Ppdf+' on the command line. Sometimes, if the same animation sequence made from graphics files is to be embedded multiple times into the document, more compact PDF output may be obtained by passing option `\verb+-dMaxInlineImageSize=0+' to \verb+ps2pdf+.

\section{The user interface}
Package `animate' provides the command
\begin{verbatim}
\animategraphics[<options>]{<frame rate>}{<file basename>}{<first>}{<last>}
\end{verbatim}
and the environment
\begin{verbatim}
\begin{animateinline}[<options>]{<frame rate>}
    ... typeset material ...
\newframe[<frame rate>]
    ... typeset material ...
\newframe*[<frame rate>]
    ... typeset material ...
\end{animateinline}
\end{verbatim}

While \verb+\animategraphics+ can be used to assemble animations from sets of existing graphics files or from multipage PDF, the environment `\verb+animateinline+' is meant to create the animation from the typeset material it encloses. This material can be pictures drawn within the \LaTeX{} `\verb+picture+' environment or using the advanced capabilities of PSTricks or pgf/TikZ. Even ordinary textual material may be animated in this way. The parameter \verb+<frame rate>+ specifies the number of frames per second of the animation.

By default, the animation is built frame by frame in the order of inclusion of the embedded material. However, extended control of the order of appearance, superposition and repetition of the material is available through the `\verb+timeline+' option (see Section~\ref{sect:timeline}).

The command \verb+\newframe+ terminates a frame and starts the next one. It can be used inside the `\verb+animateinline+' environment only. There is a starred variant, \verb+\newframe*+. If placed after a particular frame it causes the animation to pause at that frame. The animation continues normally after clicking it again. Both \verb+\newframe+ variants take an optional argument that allows to change the frame rate in the middle of an animation.

\emph{Sets of graphics files}\\[0.8\parskip]
All files of the sequence should exist and be consecutively numbered. (Exception to this rule is allowed in connexion with the `\verb+every+' option, see below.) {\tt <file base\-name>} is the leftmost part of the file name that is common to all members of the sequence. \verb+<first>+ is the number of the first and \verb+<last>+ the number of the last file in the set. File names may be simply numbered, such as $0\dots99$. If there are leading zeros, make sure that all file numbers have the same number of digits, such as $0000\dots0099$.

There is no file name extension to be specified as a parameter. The possible file formats depend on whether \LaTeX{} or pdf\LaTeX{} is used. In the case of \LaTeX{}, files with the extension `eps' are searched for at first, followed by `mps' (\MP-generated Postscript) and `ps'. With pdf\LaTeX{} the searching order is: (1)~`pdf', (2)~`mps', (3)~`png', (4)~`jpg', (5)~`jpeg', (6)~`jbig2', (7)~`jb2', (8)~`jp2'\footnotemark[1], (9)~`j2k'\footnotemark[1], (10)~`jpx'\footnotemark[1]\footnotetext[1]{JPEG2000 is not yet supported by pdf\TeX.}. That is, files capable to store vector graphics are found first. Make sure that all file names have \emph{lower case} extensions.

For example, given the sequence `frame\_5.png' through `frame\_50.png' from a possibly larger set that shall be used to build an animation running at 12 frames per second. Then, the correct inclusion command reads
\begin{verbatim}
  \animategraphics{12}{frame_}{5}{50}
\end{verbatim}

\emph{Multipage PDF inclusion (pdf\LaTeX{} only)}\\[0.8\parskip]
If the file `\verb+<file basename>+.pdf' exists (again, there is no file name extension to be specified), it is taken as a multipage document where each page represents one frame of the animation. In this case, the last two arguments, \verb+<first>+ \& \verb+<last>+, are interpreted differently from above; they specify a zero-based range of pages to be included in the animation. Either or both of them may be left empty, `\verb+{}+', in which case they default to $0$ and $n-1$, where $n$ is the total number of available pages. Arguments that fall outside this range are automatically corrected to the maximum allowed number, i.\,e. $n-1$.

For example, the line
\begin{verbatim}
  \animategraphics{12}{frames}{}{}
\end{verbatim}
would create an animation from all pages of the file `frames.pdf', running at 12 fps.

\section{Command options}
The following options to \verb+\animategraphics+ and `\verb+animateinline+' have been provided:
\subsection{Basic options}
\begin{verbatim}
poster[=first | none | last]
\end{verbatim}
Specifies which frame (first, last or none) to display and print if the animation is not activated. The first frame is shown by default. Thus `\verb+poster+' or `\verb+poster=first+' need not be explicitly set.
\begin{verbatim}
every=<num>
\end{verbatim}
Build animation from every \verb+<num>+\emph{th} frame only. Skipped frames are discarded and not embedded into the document. In the case of \verb+\animategraphics+, skipped input files may be missing.
\begin{verbatim}
autopause
\end{verbatim}
Pause animation when the page is closed, instead of stopping and rewinding it to the default frame.
\begin{verbatim}
autoplay
\end{verbatim}
Start animation after the page has opened. Also resumes playback of a previously paused animation.
\begin{verbatim}
autoresume
\end{verbatim}
Resume previously paused animation when the page is opened again.
\begin{verbatim}
loop
\end{verbatim}
The animation restarts immediately after reaching the end.
\begin{verbatim}
palindrome
\end{verbatim}
The animation continuously plays forward and backward.
\begin{verbatim}
step
\end{verbatim}
Step through the animation by one frame per mouse-click.
\begin{verbatim}
width=<width>
height=<height>
depth=<depth>
\end{verbatim}
Resize the animation widget. Any valid \TeX{} dimension is accepted as a parameter. Option `\verb+depth+' specifies how far the animation widget should extend below the bottom line of the running text. If only one or two of these options are given, the remaining, unspecified dimensions are scaled to keep the aspect ratio.
\begin{verbatim}
scale=<factor>
\end{verbatim}
Scales the animation widget by \verb+<factor>+.
\begin{verbatim}
bb=<llx> <lly> <urx> <ury>
\end{verbatim}
(\verb+\animategraphics+ only, requires package `graphicx'.) The four, space separated arguments set the bounding box of the graphics files. Units can be omitted, in which case `bp' (Postscript points) is assumed.
\begin{verbatim}
viewport=<llx> <lly> <urx> <ury>
\end{verbatim}
(\verb+\animategraphics+ only, requires package `graphicx'.) This option takes four arguments, just like `\verb+bb+'. However, in this case the values are taken relative to the origin specified by the bounding box in the graphics files.
\begin{verbatim}
trim=<left> <bottom> <right> <top>
\end{verbatim}
(\verb+\animategraphics+ only, requires package `graphicx'.) Crops the graphics at the edges. The four lengths specify the amount to be removed from or, if negative values have been provided, to be added to each side of the graphics.
\begin{verbatim}
controls
\end{verbatim}
Inserts control buttons below the animation widget. The meaning of the buttons is as follows, from left to right: stop \& first frame, step backward, play backward, play forward, step forward, stop \& last frame, decrease speed, default speed, increase speed. Both `play' buttons are replaced by a large `pause' button while the animation is playing.
\begin{verbatim}
buttonsize=<size>
\end{verbatim}
Changes the control button height to \verb+<size>+, which must be a valid \TeX{} dimension. The default button height is \verb+1.44em+ and thus scales with the current font size.
\begin{verbatim}
buttonbg=<colour>
buttonfg=<colour>
\end{verbatim}
By default, control button widgets are drawn with black strokes on transparent background. The background can be turned into a solid colour by the first option, while the second option specifies the stroke colour. The parameter \verb+<colour>+ is an array of colon-(\verb+:+)-separated numbers in the range from 0.0 to 1.0. The number of array elements determines the colour model in which the colour is defined: (1) gray value, (3) RGB, (4) CMYK. For example, `\verb+1+', `\verb+1:0.5:0.2+' and `\verb+0.5:0.3:0.7:0.1+' are valid colour specifications.
\begin{verbatim}
draft
final
\end{verbatim}
With `\verb+draft+' the animation is not embedded. Instead, a box with the exact dimensions of the animation is inserted. Option `\verb+final+' does the opposite as it forces the animation to be built and embedded. Both options can be used to reduce compilation time during authoring of a document. To get the most out of them it is recommended to set `\verb+draft+' globally as package or class option and to set `\verb+final+' locally as a command option of the animation that is currently worked on. After the document has been finished, the global `\verb+draft+' option can be removed to embed all animations.
\begin{verbatim}
begin={<begin text>}
end={<end text>}
\end{verbatim}
(`\verb+animateinline+' only.) \verb+<begin text>+ and \verb+<end text>+ are inserted into the code at start and end of each frame. Mainly used for setting up some drawing environment, such as
\begin{verbatim}
  begin={\begin{pspicture}(...)(...)}, end={\end{pspicture}}
\end{verbatim}  

\subsection{The `{\tt timeline}' option}\label{sect:timeline}
\begin{verbatim}
timeline=<timeline file>
\end{verbatim}
\verb+<timeline file>+ is a plain text file whose contents determines the order of appearance of the embedded material during the animation. In addition, it allows to freely reorder, repeat and overlay the material at any point of the animation. This may greatly reduce the file size of the resulting PDF, as objects that do not change between several or all frames, such as coordinate axes or labels, can be embedded once and re-used in other frames of the animation.

If a timeline is associated with the animation, the graphics files or inline graphics embedded by \verb+\animategraphics+ and `\verb+animateinline+' no longer represent the actual frames of the animation. Rather, they are a collection of \emph{transparencies} that can be played with at will. In order to identify the transparencies within the timeline file, they are numbered in the order of their inclusion, starting at zero.

Each line of the timeline file that is not blank and which does not begin with a comment (`\verb+%+') specifies \emph{one} frame of the animation. There may be more transparencies than animation frames and vice-versa. A frame specification consists of three, colon-(\verb+:+)-separated fields:
\begin{verbatim}
  [*]:[<frame rate>]:[<frame content>]
\end{verbatim}
While any field may be left blank, the colons are mandatory.

An asterisk (`\verb+*+') in the leftmost field causes the animation to pause at that frame, very much as a \verb+\newframe*+ would do; a number in the second field changes the frame rate of the animation section that follows. (In connexion with the `\verb+timeline+' option the asterisk extension and the optional \verb+<frame rate>+ argument of \verb+\newframe+ cease to make sense and will be tacitly ignored, if present.) The third field \verb+<frame content>+ is a comma-separated list of \emph{transparency specifications} that determines the content of the frame. A \emph{single} transparency specification obeys the syntax
\begin{verbatim}
  <transparency ID>[x<number of frames>]
\end{verbatim}
where \verb+<transparency ID>+ is an integer number that identifies the transparency to be drawn into the current animation frame. As pointed out above, the transparencies are consecutively numbered in the order of their inclusion, starting at zero. The optional postfix `\verb+x<number of frames>+' specifies the number of consecutive frames the transparency is to appear within. If omitted, a postfix of `\verb+x1+' is assumed, which causes the transparency to be shown in the current frame only. Obviously, \verb+<number of frames>+ must be a non-negative integer number. The meaning of postfix `\verb+x0+' is special; it causes the transparency to be shown in all frames, starting with the current one, until the end of the animation.

Note that the order in which transparency specifications appear in the timeline file determines their \emph{depth} level. If a frame is composed of more than one transparency, transparency specifications on the left of the input line are closer to the background and will be overprinted by those on the right which are closer to the foreground. That is, the depth \emph{de}creases from left to right within \verb+<frame content>+. Also, if there are transparency specifications which span several frames (using postfix `\verb+x<number of frames>+'), they will be overprinted by transparency specifications that appear on subsequent lines in the timeline file. That is, the depth decreases in top-down direction within the timeline file.
%The animation may be thought of as a pile of transparencies. Transparencies are always put on top of that pile, possibly overdrawing objects that are on previously deposited transparencies. Once on the pile, each transparency remains at its place for the specified number of frames and is removed afterwards. That is, for a transparency to appear always on top it must be put to the rightmost end of each line in the timeline file.

Consider the two timelines
\small
\begin{verbatim}
  ::1,0 % zeroth transparency always in the foreground
  ::2,0
  ::3,0
  ::4,0
  ...
\end{verbatim}
\normalsize
and
\small
\begin{verbatim}
  ::0x0,1 % zeroth transparency put to the background
  ::2
  ::3
  ::4
  ...
\end{verbatim}
\normalsize
In the first example, transparency No. 0 appears in the foreground throughout the animation; it will never be obscured by other transparencies' content. In the second example it is put to the background, because it is the first transparency specification in the file, and stays there for the rest of the animation.

When designing the timeline, care should be taken not to include a transparency more than once into the \emph{same} animation frame. Besides the useless redundancy, this may slow down the animation speed in the Reader, because the graphical objects of a multiply included transparency have to be rendered unnecessarily often at the same time. `animate' is smart enough to detect multiple inclusion and issues a warning message along with the transparency ID and the frame number if it occurs. Also, `animate' finds and lists transparencies that have never been used in an animation timeline. This may help to avoid dead code in the final PDF. Here is an example of a poorly designed timeline:
\small
\begin{verbatim}
  ::0
  ::1x0
  ::2
  ::3
  ::4,2
  ::5,1 % bad: transparency `1' included twice
  ::6
  ...
\end{verbatim}
\normalsize

\emph{Grouping objects into layers using `{\tt;}'}\\[0.8\parskip]
The stack-like concept of animations, where transparencies are always put on top such that they overprint the content of previously deposited transparencies, can be inconvenient in certain situations. For example, it might be desirable to allow for changing the background image in the middle of an animation without affecting objects that are located in the foreground. For this purpose, transparency specifications can be grouped into \emph{layers} using the semicolon (\verb+;+) as a separator instead of the comma. This is best illustrated by an example:
\small
\begin{verbatim}
  ::0x49;2x0,3x0    % first background image, transparency `0', used in
  ::    ;4x0,5x0    % the first 49 frames
  ::    ;6x0,7x0
  ...
  ::   ;98x0,99x0
  ::1x0;100x0,101x0 % new background image, transparency `1', until end
  ::   ;102x0,103x0 % of animation
  ::   ;104x0,105x0
  ...
\end{verbatim}
\normalsize
In this timeline, the transparencies are grouped into two layers. One is reserved for the background images, transparencies No. 0 \& 1, to be exchanged after 49 frames, and another one for the foreground objects that are successively added to the scene. As can be seen in this example, layers need not be explicitly populated; the leading semicolons just ensure the proper relationship between transparencies and animation layers. Note that \emph{without} setting up two layers, the foreground objects on transparencies 2 through 99 that have been added during the first 49 frames would be overprinted by the new background image, transparency 1, from frame 50 onward.

See the second animation, Fig.~\ref{fig:scarab}, in Section~\ref{sect:examples} for a working example that makes use of the timeline and the layer concept.

\section{Examples}
\subsection[Animations from sets of files, using `animategraphics' command]{Animations from sets of files, using {\tt \string\animategraphics} command}\label{sect:examples}
Animations in this section are made from graphics files that were prepared with \MP. Run `\verb+mpost --tex=latex+' on the files ending in `.mp' in the `doc/files' directory to generate the graphics files. Both examples make use of the `\verb+timeline+' option to reduce the resulting PDF file size.

The first example, Fig.~\ref{fig:taylor}, originally written by Jan Hole\v{c}ek~\cite{hol}, shows the exponential function $y=e^x$ and its approximation by Taylor polynomials of different degree.

\small
\begin{verbatim}
\documentclass{article}
\usepackage{animate}
\usepackage{graphics}

\begin{document}

\begin{center}
  \animategraphics[
    controls, loop,
    timeline=timeline.txt
  ]{4}{exp_}{0}{8}
\end{center}

\end{document}
\end{verbatim}
\normalsize
Contents of file `timeline.txt':
\small
\begin{verbatim}
  ::0x0 % coordinate system & y=e^x, repeated until last frame
  ::1   % one blue curve per frame
  ::2
  ::3
  ::4
  ::5
  ::6
  ::7
  ::8
\end{verbatim}
\normalsize

\begin{figure}
\centering
\animategraphics[controls,loop,timeline=timeline.txt]{4}{exp_}{0}{8}
\caption{}\label{fig:taylor}
\end{figure}

The second, somewhat more complex example, Fig.~\ref{fig:scarab}, animates the geometric construction of a scarabaeus. In addition to the use of a timeline, it introduces the layer concept. This example is adapted from Maxime Chupin's original \MP{} source file \cite{chupin}. The present version separates stationary from moving parts of the drawing and saves them into different files. A total of 254 files, scarab\_0.mps through scarab\_253.mps, is written out by running `\verb+mpost --tex=latex+' on the source file `scarab.mp'. Files 0 through 100 contain the red line segments that make up the growing scarabaeus. Files 101 through 201 contain the moving construction lines and files 202 through 252 contain the gray lines which represent intermediate stages of the construction. The last file, No. 253, contains the coordinate axes, two stationary construction lines and the labels which do not move. A timeline file is written on-the-fly during the \LaTeX{} run. It arranges the animation into three layers, forcing the gray lines into the background, the coordinate axes into the intermediate layer and the scarabaeus along with the moving construction lines into the foreground. The final animation consists of 101 individual frames.
\begin{figure}[t]
\centering
\newcounter{scarab}
\setcounter{scarab}{0}
\newcounter{blueline}
\setcounter{blueline}{101}
\newcounter{grayline}
\setcounter{grayline}{202}
%
\newwrite\TimeLineFile
\immediate\openout\TimeLineFile\jobname.tln
\whiledo{\thescarab<101}{
  \ifthenelse{\intcalcMod{\thescarab}{2}=0}{
    \immediate\write\TimeLineFile{::\thegrayline x0;253;\thescarab x0,\theblueline}
    \stepcounter{grayline}
  }{
    \immediate\write\TimeLineFile{::;253;\thescarab x0,\theblueline}
  }
  \stepcounter{scarab}
  \stepcounter{blueline}
}
\immediate\closeout\TimeLineFile
%
\animategraphics[
  width=0.8\linewidth,
  controls,
  loop,
  timeline=\jobname.tln
]{12}{scarab_}{0}{253}
%
\caption{}\label{fig:scarab}
\end{figure}

\small
\begin{verbatim}
\documentclass{article}
\usepackage{intcalc} %defines \intcalcMod for Modulo computation
\usepackage{animate}
\usepackage{graphics}

\newcounter{scarab}
\setcounter{scarab}{0}
\newcounter{blueline}
\setcounter{blueline}{101}
\newcounter{grayline}
\setcounter{grayline}{202}

%write timeline file
\newwrite\TimeLineFile
\immediate\openout\TimeLineFile\jobname.tln
\whiledo{\thescarab<101}{
  \ifthenelse{\intcalcMod{\thescarab}{2}=0}{
    %a gray line is added to every 2nd frame
    \immediate\write\TimeLineFile{%
      ::\thegrayline x0;253;\thescarab x0,\theblueline}
    \stepcounter{grayline}
  }{
    \immediate\write\TimeLineFile{%
      ::;253;\thescarab x0,\theblueline}
  }
  \stepcounter{scarab}
  \stepcounter{blueline}
}
\immediate\closeout\TimeLineFile

\begin{document}

\begin{center}
  \animategraphics[
    width=0.8\linewidth,
    controls, loop,
    timeline=\jobname.tln
  ]{12}{scarab_}{0}{253}
\end{center}

\end{document}
\end{verbatim}
\normalsize
\subsection[Animating PSTricks graphics, using `animateinline' environment]{Animating PSTricks graphics, using `{\tt animateinline}' environment}
Fig.~\ref{fig:torus} is an inline graphics example adapted from \cite{gilg05}.
\small
\begin{verbatim}
\documentclass{article}
\usepackage{pst-3dplot}
\usepackage{fp}
\usepackage{animate}

%draws a torus sector
\newcommand{\torus}[1]{% #1: angle of the torus sector
  \psset{Beta=20,Alpha=50,linewidth=0.1pt,origin={0,0,0},unit=0.35}%
  \begin{pspicture}(-12.3,-6.3)(12.3,7)%
    \parametricplotThreeD[xPlotpoints=100](80,#1)(0,360){%
      t cos 2 mul 4 u sin 2 mul add mul
      t sin 2 mul 4 u sin 2 mul add mul
      u cos 4 mul
    }%
    \parametricplotThreeD[yPlotpoints=75](0,360)(80,#1){%
      u cos 2 mul 4 t sin 2 mul add mul
      u sin 2 mul 4 t sin 2 mul add mul
      t cos 4 mul
    }%
    \FPupn\strokewidth{360 #1 sub 360 div 3 mul}%
    \parametricplotThreeD[yPlotpoints=1,linewidth=\strokewidth pt](0,360)(#1,#1){%
      u cos 2 mul 4 t sin 2 mul add mul
      u sin 2 mul 4 t sin 2 mul add mul
      t cos 4 mul
    }%
  \end{pspicture}%
}

\begin{document}

\begin{center}
\newcounter{torusangle}
\setcounter{torusangle}{80}

\begin{animateinline}[poster=last,controls,palindrome]{10}%
  \torus{\thetorusangle}%
  \whiledo{\thetorusangle<360}{%
    \newframe%
    \addtocounter{torusangle}{10}%
    \torus{\thetorusangle}%
  }
\end{animateinline}%
\end{center}

\end{document}
\end{verbatim}
\normalsize

\begin{figure}
\centering
\newcommand{\torus}[1]{% #1: angle of the torus sector
  \psset{Beta=20,Alpha=50,linewidth=0.1pt,origin={0,0,0},unit=0.35}%
  \begin{pspicture}(-12.3,-6.3)(12.3,7)%
    \parametricplotThreeD[xPlotpoints=100](80,#1)(0,360){%
      t cos 2 mul 4 u sin 2 mul add mul
      t sin 2 mul 4 u sin 2 mul add mul
      u cos 4 mul
    }%
    \parametricplotThreeD[yPlotpoints=75](0,360)(80,#1){%
      u cos 2 mul 4 t sin 2 mul add mul
      u sin 2 mul 4 t sin 2 mul add mul
      t cos 4 mul
    }%
    \FPupn\strokewidth{360 #1 sub 360 div 3 mul}%
    \parametricplotThreeD[yPlotpoints=1,linewidth=\strokewidth pt](0,360)(#1,#1){%
      u cos 2 mul 4 t sin 2 mul add mul
      u sin 2 mul 4 t sin 2 mul add mul
      t cos 4 mul
    }%
  \end{pspicture}%
}

\newcounter{torusangle}
\setcounter{torusangle}{80}
\begin{animateinline}[poster=last,controls,palindrome]{10}%
  \torus{\thetorusangle}%
  \whiledo{\thetorusangle<360}{%
    \newframe%
    \addtocounter{torusangle}{10}%
    \torus{\thetorusangle}%
  }
\end{animateinline}%
\caption{}\label{fig:torus}
\end{figure}

\section{Bugs}\label{sect:bugs}
\begin{itemize}
  \item The command {\tt\string\multido} and its relatives from package `multido' do not work if the loop body contains {\tt\string\newframe}. Use {\tt\string\whiledo} from package `if\/then' instead. (There is no need to load `if\/then' explicitly; it has already been loaded by `animate'.) A counter must be declared to keep track of the number of iterations. Further variables that take fixed point decimals to be used within the loop body can be defined and incremented by means of the commands \verb+\FPset+ and \verb+\FPeval+ from package `{\tt fp}'. For example:
\small
\begin{verbatim}

\newcounter{iter} % declare loop counter

\FPset{nInit}{1.0}% initial value of variable `n'
\FPset{nIncr}{0.5}% increment of `n'

\begin{animateinline}{12}
  %initialize loop counter and `n'
  \setcounter{iter}{0}%
  \FPset{n}{nInit}%
  ...
  ... create first frame using `\n' (Mind the backslash!)
  ... (\multido _can_ be used here!)
  ...
  \whiledo{\theiter<50}{% another 50 frames
    %start new frame
    \newframe%
    %increment loop counter by 1
    \stepcounter{iter}%
    %calculate new value of `n'
    \FPeval{n}{nInit+nIncr*\theiter}%
    ...
    ... create frame using `\n'
    ... (\multido _can_ be used here!)
    ...
  }
\end{animateinline}
\end{verbatim}
\normalsize

  \item The maximum frame rate that can actually be achieved largely depends on the complexity of the graphics and on the available hardware.

  \item The Adobe Reader setting `Use page cache' (menu `Edit' $\rightarrow$ `Preferences' $\rightarrow$ `Startup') should be \emph{dis}abled.

  \item The \verb+dvips+ option `\verb+-Ppdf+' should be avoided entirely or followed by something like `\verb+-X 2400 -Y 2400+' on the command line in order to set a sensible DVI resolution. In times of Type-1 fonts, this does \emph{not} degrade the output quality! The configuration file `config.pdf' loaded by option `\verb+-Ppdf+' specifies an excessively high DVI resolution that will be passed on to the final PDF. Eventually, Adobe Reader gets confused and will not display the frames within the animation widget.

  \item Animations do not work if the PDF has been produced with Ghostscript versions older than 8.31. This applies to all versions of ESP Ghostscript that comes with many Linux distributions.

  \item Animations with complex graphics and/or many frames may cause \LaTeX{} to fail with a `\verb+TeX capacity exceeded+' error. The following steps should fix most of the memory related problems.
  
  MiK\TeX:
  \begin{enumerate}
    \item Open a command line window.
	\item\label{item:firststep} At the DOS prompt, enter\\
	{\tt initexmf -{}-edit-config-file=latex}
	\item Type\\ 
	{\tt main\_memory=10000000}\\
	into the editor window that opens, save the file and quit the editor.
	\item\label{item:laststep} To rebuild the format, enter\\
	{\tt initexmf -{}-dump=latex}
	\item Repeat steps \ref{item:firststep}--\ref{item:laststep} with config file `{\tt pdflatex}'
  \end{enumerate}

  \TeX\ Live:
  \begin{enumerate}
	\item Find the configuration file `texmf.cnf' by means of\\
	{\tt kpsewhich texmf.cnf}\\
	at the shell prompt in a terminal.
	\item As Root, open the file in your favourite text editor, scroll to the `{\tt main\_memory}' entry and change it to the value given above; save and quit.
	\item Rebuild the formats by\\ 
	{\tt fmtutil-sys -{}-byfmt latex}\\
	{\tt fmtutil-sys -{}-byfmt pdflatex}
  \end{enumerate}

  \item Animations should not be placed on \emph{multilayered} slides created with presentation making classes such as Beamer or Powerdot. Although possible, the result might be disappointing. Put animations on flat slides only. (Of course, slides without animations may still have overlays.)

  \item Originally, package `animate' was based on a method suggested by Jan Hole\v{c}ek and Petr Soika~\cite{hol04}, but was rewritten to use Optional Content Groups (OCG). OCG-based animations are fully supported in Adobe Reader 8, but have some performance issues. Playback is usually slower in Reader 8 than in older Reader versions, which is probably a bug. The non-OCG approach performs better in Adobe Reader 8, but package/command options `\verb+autoplay+', `\verb+autopause+' and `\verb+autoresume+' do not work. Moreover, the animation position and the play/pause buttons are not properly reset on page change. This is due to usage restrictions that Adobe imposed on some important JavaScript methods in Reader 8. An old, non-OCG version of the package is still available as `animate-noocg.sty'.

\end{itemize}

\section{Acknowledgements}
I would like to thank Fran\c{c}ois Lafont who discovered quite a few bugs and made many suggestions that helped to improve the functionality of the package.

\begin{thebibliography}{8}
  \bibitem{chupin} Chupin, M.: \href{http://melusine.eu.org/syracuse/metapost/animations/chupin/?idsec=scara}{\tt http://melusine.eu.org/syracuse/metapost/animations/} \href{http://melusine.eu.org/syracuse/metapost/animations/chupin/?idsec=scara}{\tt chupin/?idsec=scara}
  \bibitem{gilg05} Gilg, J.: PDF-Animationen. In: \emph{Die \TeX nische Kom\"odie}, Issue 4, 2005, pp.~30--37
  \bibitem{hol} Hole\v{c}ek, J.: \emph{Animations in a pdf\TeX-generated PDF}. URL: \href{http://www.fi.muni.cz/~xholecek/tex/pdfanim.xhtml}{\tt http://www.} \href{http://www.fi.muni.cz/~xholecek/tex/pdfanim.xhtml}{\tt fi.muni.cz/\textasciitilde xholecek/tex/pdfanim.xhtml}
  \bibitem{hol04} Hole\v{c}ek, J. ; Sojka, P.: Animations in pdf\TeX-generated PDF. In: \emph{Lecture Notes in Computer Science}, Vol. 3130, 2004, pp.~179--191
  \bibitem{movie15} \emph{The Movie15 Package}. URL: \href{http://www.ctan.org/tex-archive/macros/latex/contrib/movie15/}{\tt http://www.ctan.org/tex-archive/macros/} \href{http://www.ctan.org/tex-archive/macros/latex/contrib/movie15/}{\tt latex/contrib/movie15}
\end{thebibliography}

\end{document}