|
|
What makes a PDF with working animations no longer work?
There are 3 cases that will make working animations in a PDF file NO longer work. For simplicity, let animation.pdf be the PDF file with working animations.
- We compress
animation.pdf with gswin64c -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=animation-compressed.pdf animation.pdf.
- We crop
animation.pdf with pdfcrop animation.pdf animation-cropped.pdf.
- We import
animation.pdf from within a LaTeX input file by using \includegraphics{animation.pdf}.
\animateinline versus \animategraphics
Recall that we cannot embed a PDF with animation into another document as what AlexG said, we have two options to solve your problem. Just choose one of the following.
- Use
animateinline environment to sandwich your animation codes, and put the environment into your host input file (which is an input file with beamer document class in your case). However this approach has 3 drawbacks: (a) you cannot use pdflatex to compile your host input file when the animation codes in PSTricks language. (b) your host input file contains both text and codes so it become long, crowded, hard-to-understand, difficult to maintain, etc, (c) compilation will take longer time because the animation codes get recompiled whenever you make any changes. That is why I suggest you to do the second option below.
- Use
\animategraphics instead of animateinline. \animategraphics allows you to import any PDF with one or more pages to be animated.
The theory is enough. Now the following will explain the second option (using \animategraphics). There are 2 steps as follows:
Solution
In my opinion, it will be better if you cut the animation code from the host input file (presentation with beamer in your case ) and paste the animation code into a single, TeXable input file. TeX the animation input file to produce a PDF output. Later, you can make use of this PDF to create many other projects such as GIF animation, PDF animation (in your case), PNG images, etc. This separation method also make your host input file neater, cleaner, readable, understandable, etc.
Let Simple.tex be the TeXable animation input file as follows:
%Simple.tex using standalone document class
\documentclass[pstricks,border=0pt]{standalone}
\usepackage{pstricks-add}
\newcommand\RotatingArrow[1]{%
\begin{pspicture}(-1,-1)(10,11)
\psframe*[linecolor=cyan,opacity=0.3](-1,-1)(10,11)
\psset{arrows=->}
\psaxes(0,0)(-0.5,-0.5)(9,10)[$x$,0][$y$,90]
\rput(4.5,0.6){\Huge{Temps = #1 s}}
\rput{#1}(4.5,5.5){%
\psset{arrowsize=5pt}
\pnode(2,0){A}
\pnode(2,3){B}
\psline[linecolor=blue](A)
\uput[0]{-#1}(A){\Huge{$\textcolor{blue}{\vec{a}}$}}
\psline[linecolor=red](A)(B)
\uput[90]{-#1}(B){\Huge{$\textcolor{red}{\vec{v}}$}}
}
\end{pspicture}}
\begin{document}
\multido{\i=0+10}{36}{\RotatingArrow{\i}}
\end{document}
For those who are unlucky to use standalone document class, the last resort is to use preview as follows. Note that standalone also uses preview internally.
\documentclass{article}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}
\newcommand\RotatingArrow[1]{%
\begin{pspicture}(-1,-1)(10,11)
\psframe*[linecolor=cyan,opacity=0.3](-1,-1)(10,11)
\psset{arrows=->}
\psaxes(0,0)(-0.5,-0.5)(9,10)[$x$,0][$y$,90]
\rput(4.5,0.6){\Huge{Temps = #1 s}}
\rput{#1}(4.5,5.5){%
\psset{arrowsize=5pt}
\pnode(2,0){A}
\pnode(2,3){B}
\psline[linecolor=blue](A)
\uput[0]{-#1}(A){\Huge{$\textcolor{blue}{\vec{a}}$}}
\psline[linecolor=red](A)(B)
\uput[90]{-#1}(B){\Huge{$\textcolor{red}{\vec{v}}$}}}
\end{pspicture}}
\begin{document}
\multido{\i=0+10}{36}{\RotatingArrow{\i}}
\end{document}
TeX it with either xelatex or latex->dvips->ps2pdf to get a PDF file. In our example, it will contain 36 pages to create a simple animation as follows.

Now, you create the beamer as follows.
\documentclass{beamer}
\usepackage{animate}
\begin{document}
\begin{frame}{Circular motion in action}
\animategraphics[autoplay,loop,scale=0.5]{10}{Simple}{}{} % WARNING: the filename must not include its extension!
\end{frame}
\end{document}
TeX it with either pdflatex (recommended) or xelatex. And the following image shows your presentation with a working animation.
The latest edit
We can also combine both input files into single input file as follows. Compile it with pdflatex --shell-escape.
\documentclass{beamer}
\usepackage{filecontents}
%====================== BEGIN FILE CONTENTS ==========================
\begin{filecontents*}{dummy.tex}
\documentclass{article}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}
\newcommand\RotatingArrow[1]{%
\begin{pspicture}(-1,-1)(10,11)
\psframe*[linecolor=cyan,opacity=0.3](-1,-1)(10,11)
\psset{arrows=->}
\psaxes(0,0)(-0.5,-0.5)(9,10)[$x$,0][$y$,90]
\rput(4.5,0.6){\Huge{Temps = #1 s}}
\rput{#1}(4.5,5.5){%
\psset{arrowsize=5pt}
\pnode(2,0){A}
\pnode(2,3){B}
\psline[linecolor=blue](A)
\uput[0]{-#1}(A){\Huge{$\textcolor{blue}{\vec{a}}$}}
\psline[linecolor=red](A)(B)
\uput[90]{-#1}(B){\Huge{$\textcolor{red}{\vec{v}}$}}}
\end{pspicture}}
\begin{document}
\multido{\i=0+10}{36}{\RotatingArrow{\i}}
\end{document}
\end{filecontents*}
%====================== END FILE CONTENTS =========================
\usepackage{animate}
\begin{document}
\immediate\write18{latex dummy}
\immediate\write18{dvips dummy}
\immediate\write18{ps2pdf dummy.ps}
\begin{frame}{Circular motion in action}
\animategraphics[controls,scale=0.5]{10}{dummy}{}{}
\end{frame}
\end{document}
|