24
  • Consider the following minimal working example.
  • It's great to have an animation in pdf format.
  • But sometimes it would be good to be able to export it into an animated gif or something else (swf, video file, svg?).
  • How do I achieve this?
  • Note: I often have animations together with pgfplots.

\documentclass{article}

\usepackage{animate}

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

\begin{document}

\begin{center}
\fboxsep1mm
    \begin{animateinline}[autoplay,loop]{2}
    a
    \newframe    
    b
    \newframe  
    c                 
    \end{animateinline}
\end{center}

\end{document}

Remark

The animation is not visible in all PDF viewers. It surely works with a current Adobe Reader.

2
  • 1
    See my answer that can produce many output format in one click. Oct 12 '13 at 15:14
  • 1
    New possibilities. See below.
    – AlexG
    Nov 30 '18 at 11:29
29
+50

1 Animated SVG (animate [2018/11/20])

  • suitable for inclusion in Web pages (or viewed standalone, also on mobile devices)
  • freely scalable (vectorial graphics)
  • relies on M. Gieseking's dvisvgm output driver/utility (available in TeXLive and MikTeX)

  • compile with

    latex myAnim.tex % or lualatex --output-format=dvi or xelatex --no-pdf
    dvisvgm --exact --font-format=woff --zoom=-1 myAnim.dvi % or myAnim.xdv
    

myAnim.tex:

    \documentclass[dvisvgm,12pt]{article}
    \usepackage{animate}
    \pagestyle{empty}

    \begin{document}\Huge
    \begin{center}

      \begin{animateinline}[controls,buttonsize=0.5em,autoplay,loop]{2}
        \multiframe{10}{i=0+1}{
          \framebox[1em]{\i}
        }
        \newframe
          \framebox[1em]{A}
        \newframe
          \framebox[1em]{B}
        \newframe
          \framebox[1em]{C}
        \newframe
          \framebox[1em]{D}
        \newframe
          \framebox[1em]{E}
        \newframe
          \framebox[1em]{F}
      \end{animateinline}

    \end{center}
    \end{document}
  • embed into HTML with the <object> tag

    <object type="image/svg+xml" data="myAnim.svg">
      <!-- fallback & search engine indexing -->
      <img src="myAnim.svg" />
    </object>
    
  • The Chromium Web browser and those derived from it (Chrome, Opera, ...) have by far the best rendering performance, as can be tested with the Lorenz attractor example.

2 Export to multipage PDF (animate [2018/08/22])

As of version [2018/08/22], animate has the package option export, to be used together with the standalone document class, as in:

\documentclass[export]{standalone}
\usepackage{animate}

or

\documentclass{standalone}
\usepackage[export]{animate}

Animation frames are output as individual pages of a multipage document, suitable for conversion to other file formats, such as animated GIF, using external programs, such as convert from ImageMagick.org:

convert -density 300 -delay 4 -loop 0 -alpha remove multipage.pdf animated.gif

creates an animated GIF at 100/4=25 frames per second.

16
  • 1
    I might add some code to animate in the future that detects whether preview was loaded and which then takes the necessary actions.
    – AlexG
    Oct 16 '13 at 11:45
  • 1
    @Dr.ManuelKuehner, thank you for your kind comments!!
    – AlexG
    Mar 13 '18 at 21:14
  • 1
    @Dr.ManuelKuehner : I updated my answer.
    – AlexG
    Aug 24 '18 at 9:17
  • 2
    Great! I only can upvote once sadly. I will upvote some other of your answers. Aug 24 '18 at 15:28
  • 1
    dvisvgm (version 2.3.5) contained in TeXLive does not support embedding external PDF, but the upstream version 2.6.1 does. It will very likely be in TeXLive-2019. For now, split-convert the multipage PDF to a numbered set of PS files and use \animategraphics....
    – AlexG
    Jan 3 '19 at 14:18
2

Animated GIFs can be made using wolfram script and latexalpha2wlua.sty (windows, pdflatex, lualatex)

See https://tex.stackexchange.com/a/579254/161015 for a complete answer.

s

\documentclass{standalone}
\RequirePackage[cache]{latexalpha2wlua} % option cache (faster on the second run) or nocache (recalculate always)

\begin{document}

Produce an animated GIF in current directory 

\newcommand{\iplotx}{% 
    Animate[Plot3D[Sin[x*y +a], {x, 0, 6}, {y, 0, 6}], {a, 0, 4}]
}

\wolframonlygif{\iplotx}{animaxvi}  %#2 name of animated gif 
    
\end{document}

In addition

(1) As part of the output an animated gif will remain in the current directory

(2) Put latexalpha2wlua.sty in the same directory of the document or in your local texmf directory.

4
  • Thanks for the follow-up! Jan 22 at 22:31
  • Where is the definition of the command \wolframonlygif? I can't find it in the package file. I think you mean \wolframanimation.
    – Diaa
    Jan 24 at 7:35
  • While digging into the script language I forgot to do the update. Sorry!! It is done now. Jan 24 at 10:37
  • +1 Somehow I forgot to upvote, sorry. May 31 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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