I want to generate animated pdf where one image is used as background and animated part which is changed in layer above. Is this possible to do with animate package?

Inspiration: Faraday motor



    \includegraphics[width=\textwidth]{example-image-a}  % Backgroung image

1 Answer 1


animateinline and \animategraphics cannot be nested.

Use TikZ nodes to align the image parts:



  \begin{tikzpicture}[inner sep=0,outer sep=0]
    \node at (0,0) {\includegraphics{down}};
    \ifthenelse{\i<15 \OR \i>45}{
      % stick in front of magnet
      \node at (-2,0.4) {\includegraphics{magnet}};
      \node at (-2,4.05) {\includegraphics{stick-\i}};
      % stick behind magnet
      \node at (-2,4.05) {\includegraphics{stick-\i}};
      \node at (-2,0.4) {\includegraphics{magnet}};
\small Images: \textcopyright\ National High Magnetic Field Laboratory

The images of the original example were downloaded and renamed with this shell script:

for i in {0..59}
    wget https://nationalmaglab.org/html5/MagLabU/source/faradaymotor/images/stickFrames/stick%20\($i\).png
    mv stick\ \($i\).png stick-$i.png
wget https://nationalmaglab.org/html5/MagLabU/source/faradaymotor/images/down.png
wget https://nationalmaglab.org/html5/MagLabU/source/faradaymotor/images/magnet.png
  • 1
    +1: This is amazing! In addition, I was not aware that an animated version of SVG exists. Feb 19, 2022 at 20:09
  • Can you point me to where I can find this project on your profile (gitlab.com/agrahn)? Feb 19, 2022 at 20:21
  • 1
    I uploaded only the SVG to my GitHub repo. If you want to produce it yourself, just add dvisvgm to the class options: \documentclass[varwidth,dvisvgm]{standalone}. First, you need the images; download them with the commands in the code box at the bottom of my answer. Then run dvilualatex twice and finally dvisvgm --zoom=-1 --bbox=papersize --font-format=woff2 on the DVI file.
    – AlexG
    Feb 19, 2022 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .