4

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
\usepackage{animate,graphicx}
\begin{document}
\animategraphics[palindrome,controls,loop,autoplay,scale=<scale>]{<frame rate>}{"<diagram filename>"}{}{}
\end{document}

whenever I want to create a standalone PDF animation.

Is there any workflow to simplify this?

4
  • related : How to create simple animations with animate? tex.stackexchange.com/q/401886/138900
    – AndréC
    Commented Dec 18, 2018 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
    Commented Dec 18, 2018 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
    Commented Dec 18, 2018 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. Commented Dec 18, 2018 at 18:27

1 Answer 1

4

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
\usepackage{animate,graphicx}
\begin{document}
\animategraphics[palindrome,controls,loop,autoplay,scale=\OutputScale]{\FrameRate}{"\InputFileName"}{}{}
\end{document}

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

Miscellaneous

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.

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

You must log in to answer this question.

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