Question: As a follow up to [Highlighting specific parts of a TikZ drawing](https://tex.stackexchange.com/questions/23548/highlighting-specific-parts-of-a-tikz-drawing), I'd like to know how to generate an animated image (`gif`) from a series of `beamer` slides.

Martin Scharrer came up with this example:

![Drawing 1](https://i.stack.imgur.com/3w9Xr.gif)

Some hints on cropping the PDF file are also welcome. `=)`

Answer: 
I generated that animated GIF the following way under Ubuntu Linux. It should work under other OSs as well because the external software is also available for Windows, Mac and others.

This assumes a `beamer` `frame` with several overlays as a starting point. The code for the GIF above can be found in my answer to [Highlighting specific parts of a TikZ drawing](https://tex.stackexchange.com/questions/23548/highlighting-specific-parts-of-a-tikz-drawing/23550#23550).

1. Ensure otherwise empty slides, e.g. `\setbeamertemplate{navigation symbols}{}%`
2. Ensure that all slides have the same size.
3. Compile to PDF (directly or indirectly).
4. Crop the PDF, e.g. using `pdfcrop <file>.pdf`.
5. Use [ImageMagick](http://www.imagemagick.org/script/index.php) to generate an animated GIF from the multi-page PDF:

```
convert -verbose -delay 50 -loop 0 -density 300 <file>-crop.pdf <file>.gif

```

Change the settings to your liking.  

`-verbose` is not really required.  

`-delay` states the duration of every image in the animation in 1/100 s.  

`-loop` states the number of repeats. `0` here means repeat indefinitely.  

`-density` determines the density for the raster image in dots-per-inch (dpi). This will influence the GIF size and is required because the PDF is a vector graphic. You can also use `300x300` etc. to select the X and Y density separately.

Here also an external example showing a diagram I had in one of my scientific publications: [MP-DPWM](https://i.imgur.com/mhphx.gif) (300k)

I might add support for this to `standalone`. Conversion support is already added in the developer version.
For those who need non Beamer version, see the following.

LaTeX Input File:
-----------------

In this illustration I use PSTricks.

```
% travelingwave.tex
\documentclass{minimal}
\usepackage{pstricks-add,multido}
\newcommand\Left{0}
\newcommand\Bottom{-0.9}
\newcommand\Right{3.14}
\newcommand\Top{0.9}

\parindent=0pt
\paperwidth=\dimexpr\Right cm\relax
\paperheight=\dimexpr\Top cm - \Bottom cm\relax
\special{papersize=\the\paperwidth,\the\paperheight}
\topmargin=-72.27pt
\oddsidemargin=-72.27pt
\pagecolor{black}

\begin{document}
\multido{\r=0+7.5}{48}
{
    \begin{pspicture*}(\Left,\Bottom)(\Right,\Top)
    \psplot[plotpoints=300,algebraic,linecolor=yellow]{\Left}{\Right}{0.9*sin(2*(x-\r*Pi/360))}
    \end{pspicture*}\newpage
}
\end{document}

```

Batch File:
-----------

```none
rem compile.bat takes a LaTeX input file without extension.
echo off
latex %1
dvips -t unknown %1
gswin32c -dAutoRotatePages=/None -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=%1.pdf %1.ps
convert -verbose -delay 25 -loop 0 -density 300 %1.pdf %1.gif
rem acrord32 %1.pdf
del %1.log
del %1.aux
del %1.dvi
del %1.ps

```

For the sake of simplicity, save both `travelingwave.tex` and `compile.bat` in the same directory. To compile, type `compile travelingwave` in DOS-command, and hit enter. Done!

Result:
-------

![enter image description here](https://i.stack.imgur.com/7TDPm.gif)

Notes:
------

1. See [ImageMagick v6 Examples -- Animation Basics](http://www.imagemagick.org/Usage/anim_basics/) for the detailed description about `convert`'s switches.
2. If `\pagecolor{<any-color-including-white>}` is disabled, we will get an effect as follows. 
![enter image description here](https://i.stack.imgur.com/Wf9DS.gif)
3. ImageMagick's `convert` invokes GhostScript `gswin32c.exe` behind the scene as follows.
![enter image description here](https://i.stack.imgur.com/I7dHQ.png)