I have a PDF file consisting of several pages. How to generate a standalone PDF animating those pages?

More detailed skenario

I create a bunch of diagrams everyday. Sometimes I want to animate each diagram in either GIF or PDF. It will be tedious if I have to create a new file as follows

\documentclass[border=12pt]{standalone}% cannot use preview
\animategraphics[palindrome,controls,loop,autoplay,scale=<scale>]{<frame rate>}{"<diagram filename>"}{}{}

whenever I want to create a standalone PDF animation.

Is there any workflow to simplify this?

  • related : How to create simple animations with animate? tex.stackexchange.com/q/401886/138900 – AndréC Dec 18 '18 at 17:01
  • Yours is too short: we don't know on which operating system you are running the batch: Mac, Unix, Windows, Linux? mine answers the question that was asked by being as simple as possible and as short as possible (if it is possible to answer such a question in a short way) and it is completely independent of the operating system. – AndréC Dec 18 '18 at 17:24
  • In my answer I give two different ways to use the animate package. It's true that it's a long time. Should I cut this answer in half and write two answers instead of one? – AndréC Dec 18 '18 at 17:33
  • I have deleted my previous comment but the point was that I think the answer given by AndreC should be split into several shorter answers for the sake of simplicity. – Kim Jong Un Dec 18 '18 at 18:27

Microsoft Windows Users

For other operating systems, please rise your both hands.

Create a template file, name it template.tex, save it below the local texmf folder (I am not sure my terminology is correct here).

\documentclass[border=12pt]{standalone}% cannot use preview

Create a batch file as follows. Name it, for example, animator.bat. Save it in any safe place and register its path to PATH to make it accessible from everywhere.

echo off

rem %1 PDF filename without extension
rem %2 frame rate
rem %3 scale

if exist "%~1.pdf" rename "%~1.pdf" "%~1-animate.pdf"

rem need 2 compilations
if exist "%~1-animate.pdf" pdflatex -interaction=batchmode --jobname="%~1" "\def\InputFileName{%~1-animate}\def\FrameRate{%2}\def\OutputScale{%3}\input{template}"
if exist "%~1-animate.pdf" pdflatex --jobname="%~1" "\def\InputFileName{%~1-animate}\def\FrameRate{%2}\def\OutputScale{%3}\input{template}"

if exist "%~1-animate.pdf" del "%~1-animate.pdf"

for %%x in (aux log out toc) do (if exist "%~1.%%x" del "%~1.%%x")

Now you can call the batch animator.bat as follows.

animator mypdffilenamewithoutextension 25 1

Done, see the result. A standalone PDF animation viewed on Acrobat Reader.

enter image description here


You can also create a new build profile (in TeXnicCenter, TeXStudio, or any editors) to invoke the batch such that you can save more time and energy.

  • 3
    now the hard part: convert this into some file having a decent extension such as ".sh" for Linux :) – user4686 Dec 18 '18 at 13:46

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.