circuitikz vs. tikzpicture: generating multipage standalone documents for animations

This is a problem I found a while ago, and haven't been able to figure out. Maybe is something wrong with my distribution, but don't know exactly how to fix it. Here is the idea

Consider this script

\documentclass[border = 5pt, tikz]{standalone}
\usepackage{circuitikz}

\begin{document}
\foreach \k in {1,...,10}
{
\begin{tikzpicture}
\draw (0, 0) rectangle (2, 2);
\fill[red] (\k/5, 1) circle (0.1);
\end{tikzpicture}
}
\end{document}


When I run it, it produces 10 pages which then I can use to produce a gif

If on the other hand I change the enviroment to circuitikz

\documentclass[border = 5pt, tikz]{standalone}
\usepackage{circuitikz}

\begin{document}
\foreach \k in {1,...,10}
{
\begin{circuitikz}
\draw (0, 0) rectangle (2, 2);
\fill[red] (\k/5, 1) circle (0.1);
\end{circuitikz}
}
\end{document}


I get one single page with all frames on it

and then transforming this to a gif has proven a bit difficult to do.

Any ideas as to why this is happening? Thanks!

I'm using Version 3.14159265-2.6-1.40.19 (TeX Live 2018/MacPorts 2018.47642_7)

• I didn't know that standalone could produce more than a single page document. – Sigur Jan 7 at 19:27
• @Sigur Many animations are produced by producing a multipage pdf first and then convert this to an animated gif via convert -density <density> -delay <delay> -loop 0 -alpha remove multipage.pdf anited.gif. – user121799 Jan 7 at 19:32
• @Sigur Yes, it does. If you compile the fist file in the above question, you get a multipage pdf. – user121799 Jan 7 at 19:38
• Btw, shouldn't animated SVG be the preferred format nowadays ;-) ? – AlexG Jan 8 at 4:46
• The tikz option not only loads tikz, it also sets [multi=tikzpicture] (which is not always a good thing to do). [multi={circuitikz,tikzpicture}] is what you want. – John Kormylo Jan 8 at 16:19

If you say \documentclass[border = 5pt, tikz]{standalone} this does not just load tikz but also tells standalone that it should produce single pdf pages for each tikzpicture. In order to generate separate pdf pages for circuitikz you could do

\documentclass[border = 5pt, tikz]{standalone}
\usepackage{circuitikz}
\standaloneenv{circuitikz}
\begin{document}
\foreach \k in {1,...,10}
{
\begin{circuitikz}
\draw (0, 0) rectangle (2, 2);
\fill[red] (\k/5, 1) circle (0.1);
\end{circuitikz}
}
\end{document}


Note that this possibility is not unique. Another possibility is to use

\documentclass[border = 5pt, multi={circuitikz}]{standalone}
\usepackage{circuitikz}
\begin{document}
\foreach \k in {1,...,10}
{
\begin{circuitikz}
\draw (0, 0) rectangle (2, 2);
\fill[red] (\k/5, 1) circle (0.1);
\end{circuitikz}
}
\end{document}


instead. For further information, please consult the standalone manual on p. 10.

• Note to myself: next time ask sooner :) Thanks a bunch – caverac Jan 7 at 19:33
• This MWE will be very useful in the future. – Sigur Jan 7 at 19:38

The same as an animated SVG, using the animations library of TikZ/Pgf-3.1:

Compile with

latex example
dvisvgm --zoom=-1 example


example.tex:

\documentclass[dvisvgm]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{animations}

\begin{document}

\begin{circuitikz}
\draw (0, 0) rectangle (2, 2);
\scoped [name=circle, animate = {
object=circle, :shift = { 0s = "{(1/5,1)}", 3s = "{(2,1)}", repeats }
}
] \fill[red] (0,0) circle (0.1);
\end{circuitikz}

\end{document}

• Amazing, was this introduced in 3.1? – caverac Jan 8 at 12:10