6

I am using TikZ externalization to compile the figures in my thesis that use TikZ or PGF Plots. Ever since I included an animation using the animate package, the size of the PDFs of each of my externalized figures has increased significantly - by almost exactly the same size as the animation increases my final compiled PDF.

Example: in the MWE below, I have an externalized TikZ figure and an animation. There are three cases:

  • Case 1: The animation is commented out and excluded
  • Case 2: The animation and TikZ file are both included
  • Case 3: The externalized TikZ file is excluded

Now in case 1, the file sizes are as follows:

  • animateMWE.pdf: 9,002 bytes
  • extfig-pdfout.pdf: 1,175 bytes

In case 2, the file sizes are:

  • animateMWE.pdf: 594,282 bytes
  • extfig-pdfout.pdf: 584,854 bytes

Case 3:

  • animateMWE.pdf: 593,569 bytes

Note how the "excess data" in the externalized file does not contribute to the size of the final compiled document. The document at the end isn't overly inflated in size, but all of the externalized PDF output files are. So it's not a thesis-breaking issue, merely a matter of curiosity.

Why does this occur?

The source files (which include the animation) are available on Dropbox. Compilable with pdflatex -shell-escape animateMWE.

animateMWE.tex:

\documentclass[]{article}

\usepackage{animate}
\usepackage{pgfplots}   
\usepgfplotslibrary{external}

\makeatletter
\newcommand{\useexternalfile}[1]{%
    \tikzsetnextfilename{#1-pdfout}%
    \input{\tikzexternal@filenameprefix#1.tikz}}
\makeatother

\tikzexternalize
\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}}

\tikzset{external/force remake=true}

\begin{document}

\begin{figure}
\centering
\animategraphics[height=8cm,controls,loop]{10}{./3-3mode/img-}{0}{39}
\end{figure}

\begin{figure}
\centering
\useexternalfile{extfig}
\end{figure}

\end{document}

extfig.tikz:

\begin{tikzpicture}
  \draw (-1.5,0) -- (1.5,0);
  \draw (0,-1.5) -- (0,1.5);
  \draw (0,0) circle (1cm);
\end{tikzpicture}
1
  • This seems to be a peculiarity of TiKZ externalization. I had a look into extfig-pdfout.pdf; all frames of the animation are contained therein as PDF XObjects (referable [=repeatable] image objects), but are unused (= dead code).
    – AlexG
    Feb 13 '14 at 9:18
4

During externalization, not only the tikzpicture environment in question is processed but also the rest of the page including the \animategraphics command. The latter uses the \pdfxform primitive of pdfTeX to encapsulate animation frames into PDF XObjects, which are inserted into the externalized graphics file and contribute to the file size, but which remain unused.

This can be avoided using the following workaround:

\tikzifexternalizing{}{\animategraphics[height=8cm,controls,loop]{10}{./3-3mode/img-}{0}{39}}
1
  • Huh, odd behaviour. This fixes it even for TikZ figures in different chapters.
    – Moriarty
    Feb 13 '14 at 20:04

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.