[Tex/LaTex] Problems to get \animategraphics from animate package working properly in beamer

animatebeamer

I recently discovered the animate package (actually it was here, looking for alternatives I came across this: https://tex.stackexchange.com/a/235180/212085) and I want to generate two different versions of my beamer slides for a course:

  • PDF (with no animation at all if you use free software viewers as I do)
  • SVG (with animations, viewing the slides in a browser)

My problems start when I try to get running the most simple example with \animategraphics in a beamer slide. I am able to get a standalone document working ok, the issue arises when using the beamer document class. I tried several examples I found with \animateinline and they work flawlessly (for example, the svgbeamer.tex file that AlexG provides in https://tex.stackexchange.com/a/235180/212085)… but I can not get it to work with a very simple \animategraphics prototype.

For my first example I'm using this public domain annimated gif (https://upload.wikimedia.org/wikipedia/commons/e/e7/Simple_raycasting_with_fisheye_correction.gif) and after slice it in the corresponding 40 frames with ImageMagick's convert (I generated PNG and EPS files to try both LaTeX and XeLaTeX).

Using the minimal template provided by the author in the official doc, I wrote this simple beamer example (example.tex):

\documentclass[dvisvgm,aspectratio=169]{beamer}

\usepackage{animate}
%\usepackage{graphicx} % already included by beamer
%\usepackage{tikz}     % already included by beamer

\begin{document}

\begin{frame}{Simple raycasting animation}
    \animategraphics[controls,loop,autoplay]{16}{tmp/raycasting_frame}{00}{39}
\end{frame}

\end{document}

then

latex example
latex example

… and the DVI file looks Ok (static, but Ok). Then:

dvisvgm --font-format=woff --zoom=-1 -p1,- example

creates the SVG file and provides this feedback:

pre-processing DVI file (format version 2)
processing page 1
  graphic size: 455.24408pt x 256.074799pt (159.999995mm x 89.999998mm)
  output written to example.svg
1 of 1 page converted in 2.84687 seconds

However, the animation seems to be "out" of the viewport in the SVG. Only the title of the slide and the controls are visible when rendering the file in the browser, and opening it with Inkscape shows the picture below the slide. Here you can get both files (DVI and SVG) to know what I mean:

Curiously (or not), if I remove the dvisvgm parameter from the document class the final SVG has the picture in the viewport and perform the whole animation just once (and quite fast), but controls do not work. In this case, the picture does not appear in the previous DVI file 😕

UPDATE:

After the kind answers I have just checked the multi-page PDF approach (I'd rather this alternative than using PNG or EPS images) and I do not detect any change when opening the SVG from browser but I can not see now the picture at all when opening it with Inkscape (so I assume it was not been embedded in the SVG, as the file size corroborates).

These are the new files I have generated using the multi-pdf method:

The process now was:

xelatex -no-pdf example2
xelatex -no-pdf example2
dvisvgm --font-format=woff --zoom=-1 -p1,- example2.xdv

dvisvgm provided this output:

pre-processing DVI file (format version 7)
processing page 1
  graphic size: 455.24408pt x 256.074799pt (159.999995mm x 89.999998mm)
  output written to example2.svg
1 of 1 page converted in 0.283845 seconds

The only change in example.tex (now example2.tex) was the \animategraphics invocation:

\animategraphics[controls,loop,autoplay,width=\linewidth]{16}{tmp/raycasting_frame}{}{}

I have also added the output from dvisvgm in the previous text (when using latex and EPS files instead of xelatex and A multi-page PDF).

By the way, I am using TeXLive-2019 (so dvisvgm 2.9) in a Debian system.

UPDATE2:

I have updated TeXLive from 2019 to 2020 (I have used Debian experimental packages) and I downloaded and compiled dvisvgm 2.9.1 (from https://dvisvgm.de)… and that did the trick! (at least for the EPS files approach)

Now the example.svg file generated from example.tex doing latex example; latex example; dvisvgm --font-format=woff --zoom=-1 -p1,- example runs the animation perfectly.

I am still stuck with the multi-page PDF alternative, though. Following @AlexG advice I have added \usepackage{pdfbase} to the preamble of example3.tex (that is the only difference with example2.tex) and after xelatex -no-pdf example3; xelatex -no-pdf example3; dvisvgm --font-format=woff --zoom=-1 -p1,- example3.xdv I get these files (I am also attaching the log file):

Best Answer

Package xcolor (slurped in by beamer) loads the wrong driver file xetex.def for graphics and color, although dvisvgm is passed as a global option to the beamer document class. xcolor doesn't know about dvisvgm and uses xetex.def as default.

In order to be able to process the input with xelatex --no-pdf for the dvisvgm back-end, we enforce dvips.def to be used by xcolor. dvips.def uses the same definitions for colour as dvisvgm.def. We can do so by loading xcolor with the correct driver option before the document class. On the long run, pkg xcolor should be updated to be aware of dvisvgm.

Then, our multipage PDF raycasting_frame.pdf with the animation frames is embedded using the correct low-level commands (\specials).

Example code to be compiled with xelatex --no-pdf (or another DVI/XDV-making engine) + dvisvgm --zoom=-1 --font-formt=woff2 --page=- --bbox=papersize

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Force graphicx/color driver `dvips.def'
\RequirePackage[dvips]{xcolor}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[dvisvgm,aspectratio=169]{beamer}

\usepackage{animate}
%\usepackage{graphicx} % already included by beamer
%\usepackage{tikz}     % already included by beamer

\graphicspath{{tmp/}}

\begin{document}

\begin{frame}{Simple raycasting animation}
    \animategraphics[controls,loop,autoplay,width=\linewidth]{16}{raycasting_frame}{}{}
\end{frame}

\end{document}

Get raycasting_frame.pdf from Simple_raycasting_with_fisheye_correction.gif with:

convert -coalesce Simple_raycasting_with_fisheye_correction.gif raycasting_frame.pdf
Related Question