1

I want to create a small animation using tikz and animate. In order to crop the draw, I use preview package. Without it I obtain an animation that works fine but when I activate preview I am not able to play the animation.

In the following MNWE, you can obtain the right animation by commenting the lines

\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{10pt}
\begin{preview}
\end{preview}

For opening the file, I use Acrobat Reader 11 on OSX 10.10.5.

MNWE:

\documentclass{article}


\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds}
\usepackage{animate}
\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{10pt}

%data
\def\itMax{100}
\def\pas{1}
\def\vMax{5}
\def\vMin{-5}
%
\newcommand{\plotPerso}[1]{
\begin{tikzpicture}
%
\draw (-5,\vMin) rectangle (5,\vMax);
\draw[black,very thick] (-5,0) -- (0,#1);
\draw[black,very thick] (5,0) -- (0,#1);
\begin{pgfonlayer}{background}
    \path[fill=brown!20] (-5,\vMin) rectangle (5,\vMax);
\end{pgfonlayer}
\end{tikzpicture}
}


\begin{document}
\begin{preview}
\begin{animateinline}[loop, poster = first, controls,autoplay]{60}
\multiframe{\itMax}{icount=1+\pas}
{
\pgfmathsetmacro\incrP{\vMin+((\vMax-\vMin)/\itMax)*\icount}    
\plotPerso{\incrP}
%\newframe
}
\end{animateinline}
\end{preview}
\end{document}
1
  • Have you already tried standalone class as an alternative?
    – AlexG
    Nov 2, 2017 at 11:10

1 Answer 1

2

preview heavily manipulates the shipout routine of TeX. Some entries of the PDF /Catalog object, e. g. the /AcroForm dictionary, are not written upon finalizing the PDF file.

I suggest using the standalone class, which seems to do a better job here.

There are unprotected line endings (missing %) in the original code which produce spurious space, leading to uneven margins around the animation, namely

\newcommand{\plotPerso}[1]{% <-- `%' added
...
\pgfmathsetmacro\incrP{\vMin+((\vMax-\vMin)/\itMax)*\icount}% <-- `%' added

These are corrected in the code:

\documentclass[margin=10pt]{standalone}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds}
\usepackage{animate}

%data
\def\itMax{100}
\def\pas{1}
\def\vMax{5}
\def\vMin{-5}

\newcommand{\plotPerso}[1]{%
  \begin{tikzpicture}
    \draw (-5,\vMin) rectangle (5,\vMax);
    \draw[black,very thick] (-5,0) -- (0,#1);
    \draw[black,very thick] (5,0) -- (0,#1);
    \begin{pgfonlayer}{background}
      \path[fill=brown!20] (-5,\vMin) rectangle (5,\vMax);
    \end{pgfonlayer}
  \end{tikzpicture}
}


\begin{document}
\begin{animateinline}[loop, poster = first, controls,autoplay]{60}
\multiframe{\itMax}{icount=1+\pas}
{
  \pgfmathsetmacro\incrP{\vMin+((\vMax-\vMin)/\itMax)*\icount}%    
  \plotPerso{\incrP}
}
\end{animateinline}
\end{document}
2
  • Thank you for your answer. I have used it in the past but I stopped using it due to bad size of margins. In this case the result is almost ok: the animation works well but the left margin is slightly larger than the right one.
    – Guuk
    Nov 2, 2017 at 13:06
  • 1
    There are a number of unprotected (missing %) line endings in your code that produce (add up to) the spurious space in front of the animation.
    – AlexG
    Nov 2, 2017 at 13:51

You must log in to answer this question.

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