6

I'm trying to speed-up compilation of my multi-tikz .tex file.

I found this topic and successfully applied the solution ; unfortunately, it doesn't work for animations inside the tikzfigure: Only the first view of the animation is rendered on the final pdf.

Question: Is there a way to make tikz external work with beamer's animations?

The tikzset I use for my animations is the following (found also on texSE):

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
        \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}

Here is a full document that illustrate the issue:

\documentclass{beamer}
\usepackage{pgfplots}              % handle plots
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{external}
    \tikzexternalize[mode=list and make, prefix=tikz/]
    \tikzset{external/system call={pdflatex \tikzexternalcheckshellescape
        -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"}
    } % to let pdflatex work

\tikzset{
    invisible/.style={opacity=0},
    visible on/.style={alt={#1{}{invisible}}},
    alt/.code args={<#1>#2#3}{%
        \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}
\begin{document}

\begin{frame}
    \begin{tikzpicture}
        \node[draw] at (0,0) {auie};
        \pause
        \node[draw] at (1,0) {tsrn};
        \node[draw,visible on=<3->] at (1,1) {vdlj};
    \end{tikzpicture}
\end{frame}
\end{document}
3
  • 2
    Welcome to TeX.SE! Please provide us with a complete minimal example, i.e. document that starts with \dcoumentclass and ends with \end{document}. BT, perhaps something like this answer helps or is at least a good starting point.
    – user121799
    Commented Oct 5, 2018 at 16:42
  • created a complete minimal example
    – Jav
    Commented Oct 5, 2018 at 16:51
  • 1
    Thanks! Notice that visible on etc. is part of the very useful library overlay-beamer-styles, whose only disadvantage is that nobody can recall its name. ;-)
    – user121799
    Commented Oct 5, 2018 at 16:59

2 Answers 2

6

Thanks for your MWE! Here is an example entirely based on this answer. You will see that if you compile it the second time, the external pictures will be loaded, so compilation is faster.

\documentclass{beamer}
%\url{https://tex.stackexchange.com/q/119428/86}
\usepackage{tikz}

\usetikzlibrary{external}
\usetikzlibrary{overlay-beamer-styles}

\makeatletter
\newcommand*{\overlaynumber}{\number\beamer@slideinframe}
\tikzset{
  beamer externalizing/.style={%
    execute at end picture={%
      \tikzifexternalizing{%
        \ifbeamer@anotherslide
        \pgfexternalstorecommand{\string\global\string\beamer@anotherslidetrue}%
        \fi
      }{}%
    }%
  },
  external/optimize=false
}
\let\orig@tikzsetnextfilename=\tikzsetnextfilename
\renewcommand\tikzsetnextfilename[1]{\orig@tikzsetnextfilename{#1-\overlaynumber}}
\makeatother

\tikzset{every picture/.style={beamer externalizing}}

\tikzexternalize

\begin{document}

\begin{frame}[t]{\texttt{overlay-beamer-styles} and \texttt{externalize}}
\begin{itemize}
  \item<1-> Image 1
  \item<2-> Image 2
  \item<3-> Image 3
\end{itemize}
  \tikzsetnextfilename{figure}
  \begin{tikzpicture}
    \node (1) {Overlay 1};
    \draw[-latex,visible on={<2->}] (1.east) -- ++ (1,0) node[right] (2) {Overlay 2};
    \draw[-latex,visible on={<3->}] (2.east) -- ++ (1,0) node[right] (3) {Overlay 3};
  \end{tikzpicture}
\end{frame}

\end{document}

enter image description here

7
  • it's recompiling the whole document (with figures) even if the change is not in a tikzpicture. BTW, the figures are wrong when I set \setbeameroption{show notes on second screen}
    – Jav
    Commented Oct 9, 2018 at 6:48
  • @Jav No, this is not true. It only recompiles when you change the figures. BTW, what is \setbeameroption{show notes on second screen}? On my distribution that just causes an error.
    – user121799
    Commented Oct 9, 2018 at 11:17
  • from pgfpages : allows to create a double sized frame with the frame on the left, and the notes on the right
    – Jav
    Commented Oct 9, 2018 at 11:20
  • 1
    @Jav Either make qualified statements or please refrain from posting random comments. I just told you that your command throws an error. So I do not think that your comment addresses this in any way. And the first part of your above comment is just not true.
    – user121799
    Commented Oct 9, 2018 at 11:23
  • 1
    @Jav You are making statements that cannot be reproduced. I tested my code 20 times and cannot confirm what you are saying. And then you tell that the figures are wrong if you use \setbeameroption{show notes on second screen}, but this command simply causes an error. What should I say? I just think that you do not run my code at all.
    – user121799
    Commented Oct 9, 2018 at 11:47
2

The previous answer solves the MWE in the question, but my experience is that the visible on=<overlay specification> tikzset and overlay-beamer-styles are not compatible with tikzexternalize when the figure contains transparency. Note this occurs even when setting opacity=1. Using the standard beamer overlay specification (e.g. \draw<1->), however, works as expected, and therefore may be a more general solution.

enter image description here

Oddly, the incorrect behavior is a bit different depending if the transparency is in a graphic included with \includegraphics vs a tikz drawing. Based on this limitation, it seems better to avoid the overlay-beamer-styles format or the "visible on" tikzset if externalizing figures with transparency might be needed.

Modified MWE to highlight this issue:

\documentclass{beamer}
%\url{https://tex.stackexchange.com/q/119428/86}
\usepackage{tikz}

\usetikzlibrary{external}
\usetikzlibrary{overlay-beamer-styles}

\makeatletter
\newcommand*{\overlaynumber}{\number\beamer@slideinframe}
\tikzset{
  beamer externalizing/.style={%
    execute at end picture={%
      \tikzifexternalizing{%
        \ifbeamer@anotherslide
        \pgfexternalstorecommand{\string\global\string\beamer@anotherslidetrue}%
        \fi
      }{}%
    }%
  },
  external/optimize=false
}
\let\orig@tikzsetnextfilename=\tikzsetnextfilename
\renewcommand\tikzsetnextfilename[1]{\orig@tikzsetnextfilename{#1-\overlaynumber}}
\makeatother

\tikzset{every picture/.style={beamer externalizing}}

\tikzexternalize

\begin{document}

  \begin{frame}{\texttt{overlay-beamer-styles} and \texttt{externalize}}
    \tikzsetnextfilename{figure0}
    \begin{tikzpicture}
       \node (1) {Overlay 1};
       \draw[-latex,visible on={<2->},opacity=0.5] (1.east) -- ++ (1,0) node[right] (2) {Overlay 2};
       \draw[-latex,visible on={<3->},opacity=1] (2.east) -- ++ (1,0) node[right] (3) {Overlay 3};
    \end{tikzpicture}
  \end{frame}

  \begin{frame}{\texttt{overlay specification} and \texttt{externalize}}
    \tikzsetnextfilename{figure1}
    \begin{tikzpicture}
      \node (1) {Overlay 1};
      \draw<2->[-latex,opacity=0.5] (1.east) -- ++ (1,0) node[right] (2) {Overlay 2};
      \draw<3->[-latex,opacity=1] (2.east) -- ++ (1,0) node[right] (3) {Overlay 3};
    \end{tikzpicture}
  \end{frame}
\end{document}

You must log in to answer this question.

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