4

I am working on a document where I want to embed animations using the animate package. A minimal compilable example of such would be the following:

\documentclass{article}


\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\usepackage{tikz}
\usepackage{media9}
\usepackage{animate}

\usepackage{amsmath}


\begin{document}

\newenvironment{tikzframe}[2]{
\begin{tikzpicture}
\draw[very thin, color=white] (0,0) rectangle (#1,#2); 
}
{
\end{tikzpicture}
}

\mediabutton[jsaction={anim['graph_switch'].frameNum=0;}]{
\fbox{$\text{sin}(x)$}
}
\mediabutton[jsaction={anim['graph_switch'].frameNum=1;}]{
\fbox{$\text{sin}(2x)$}
}
\mediabutton[jsaction={anim['graph_switch'].frameNum=2;}]{
\fbox{$\text{sin}(3x)$}
}
\begin{animateinline}[label=graph_switch,width=8cm,height=5cm,step]
\newframe{
\begin{tikzframe}{8}{5}
\begin{axis}[
xlabel={$x$},
ylabel={$\text{sin}(x)$},
xmin=-pi,xmax=pi,
]
\addplot[black,samples=101] {sin(x*180./pi)};
\end{axis}
\end{tikzframe}
}
\newframe{
\begin{tikzframe}{8}{5}
\begin{axis}[
xlabel={$x$},
ylabel={$\text{sin}(2x)$},
xmin=-pi,xmax=pi,
]
\addplot[black,samples=101] {sin(2.*x*180./pi)};
\end{axis}
\end{tikzframe}
}
\newframe{
\begin{tikzframe}{8}{5}
\begin{axis}[
xlabel={$x$},
ylabel={$\text{sin}(3x)$},
xmin=-pi,xmax=pi,
]
\addplot[black,samples=101] {sin(3.*x*180./pi)};
\end{axis}
\end{tikzframe}
}
\end{animateinline}

\end{document}

The example above consists of three buttons and a graph. The buttons allow to switch between plots of sin(x) with different frequencies:

enter image description here

The image above is what this looks like with Adobe Acrobat (acroread), but it doesn't show at all on either Okular or Evince (I haven't tried anything else), which just show a white page.

I know that the animation itself doesn't show on these viewers and I am not intending to get this fixed. What I would like to know instead is how to set a "default" static graph, for instance sin(2x) in the present example, such that at least this shows in viewers other than acroread. Is this possible?

2 Answers 2

2

Version [2014/11/27] of animate extends option poster to also accept a zero-based frame number, not just first, last or none. Thus, to show the second frame of the animation as the default frame, i. e. sin(2x), as requested in the OP, put poster=1 to the option list. This frame is also shown in viewers which do not support JavaScript-based animations.

OP's example with corrections:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\usepackage{tikz}
\usepackage{media9}
\usepackage{animate}[2014/11/27]

\usepackage{amsmath}

\begin{document}

\mediabutton[jsaction={anim['graph_switch'].frameNum=0;}]{%
  \fbox{$\text{sin}(x)$}%
}
\mediabutton[jsaction={anim['graph_switch'].frameNum=1;}]{%
  \fbox{$\text{sin}(2x)$}%
}
\mediabutton[jsaction={anim['graph_switch'].frameNum=2;}]{%
  \fbox{$\text{sin}(3x)$}%
}
\begin{animateinline}[
  poster=1, % sin 2x (frames are numbered in zero-based manner)
  width=7.5cm,
  label=graph_switch,
  begin={\begin{tikzpicture}},
  end={\end{tikzpicture}},
%  nomouse,
  step
]{0}
  \begin{axis}[
    xlabel={$x$},
    ylabel={$\text{sin}(x)$},
    xmin=-pi,xmax=pi]
    \addplot[black,samples=101] {sin(x*180./pi)};
  \end{axis}
\newframe
  \begin{axis}[
    xlabel={$x$},
    ylabel={$\text{sin}(2x)$},
    xmin=-pi,xmax=pi]
    \addplot[black,samples=101] {sin(2.*x*180./pi)};
  \end{axis}
\newframe
  \begin{axis}[
    xlabel={$x$},
    ylabel={$\text{sin}(3x)$},
    xmin=-pi,xmax=pi]
    \addplot[black,samples=101] {sin(3.*x*180./pi)};
  \end{axis}
\end{animateinline}

\end{document}
0

Apparently, the main issue here is that I had used \newframe at the beginning of the animateinline environment. This is wrong since one should only use \newframe to separate frames. Therefore the first frame's content should not be preceded by any \newframe command. When I remove that, both Okular and Evince show the (static) contents of the first frame (although the animation is still not playing). I'll still accept an answer with a recipe that allows to choose which one this default static frame should be.

You must log in to answer this question.

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