# How to create an SVG animation from a single common input file that is also used by others?

I have a single input file as follows.

% input.tex
\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
\begin{document}
\multido{\i=25+25,\r=2.5+2.5}{144}{%
\pspicture[algebraic,plotpoints=\i,linecolor=red](-2.1,-2.1)(2.1,2.1)
\parametricplot{0}{\r}{2*sin(7*t*Pi/180)|2*cos(11*t*Pi/180)}
\endpspicture}
\end{document}


I want this input file to be reusable everywhere.

Write once, reuse everywhere!

## Case 1 (imported as a still image)

If we compile input.tex (compilation: latex-dvips-ps2pdf or xelatex) to produce a multipage PDF, the last page can be imported from within another input file (compilation: pdflatex) with \includegraphics[page=144]{input.pdf}.

## Case 2 (imported to create a PDF animation)

If we compile input.tex (compilation: latex-dvips-ps2pdf or xelatex) to produce a multipage PDF, the PDF can be imported from within another input file (compilation: pdflatex) with \animategraphics[...]{...}{input.pdf}{}{} to get a PDF animation.

## Case 3 (converted to create a GIF animation)

If we compile input.tex (compilation: latex-dvips-ps2pdf or xelatex) to produce a multipage PDF, the PDF can be converted by ImageMagick to get a GIF animation.

## Case 4 (converted to create a series of PNG or JPEG images)

If we compile input.tex (compilation: latex-dvips-ps2pdf or xelatex) to produce a multipage PDF, the PDF can be converted by ImageMagick to get a series of PNG or JPEG images.

## Case 5 (converted to create a series of SVG images)

If we compile input.tex (compilation: latex-dvisvgm) to produce a series of SVG images.

# Questions

How to create an SVG animation with control panels (play, pause, forward, backward, etc) from the same input.tex? I call it as the 6th case and the last case is to create an SVG animation without control panels.

Constraint: I don't want to modify the input.tex by sandwiching with \animateinline directly.

• Though possible, what is the purpose of producing series of SVG? – AlexG Jan 3 at 15:47
• I am asking, because creating an animated SVG (as requested in the title) from a series of SVG leaves the SVG files of the series external. (They must be shipped together with the main SVG.) It is better to create the animated SVG from a series of PS files. They will be converted to inline SVG code, making the animated SVG self-contained. – AlexG Jan 3 at 15:56

## 1 Answer

input.tex can be used as is, for all cases, to first produce DVI

latex input


Further processing:

## cases 1 to 4

dvips input
ps2pdf input.ps output.pdf


## case 5 (series of numbered SVG)

dvisvgm --exact --font-format=woff --zoom=-1 -p1,- --output=output-%p.svg input

# on windows
dvisvgm --exact --font-format=woff --zoom=-1 -p1,- --output=output-%%p.svg input


## case 6 (animated SVG from series of PS)

dvips input

pdf2ps -sOutputFile=output-%d.ps input.ps
# on windows
pdf2ps -sOutputFile=output-%%d.ps input.ps


File master.tex for producing the animated SVG:

\documentclass[dvisvgm]{article}

\usepackage{animate}
\usepackage{graphicx}
\pagestyle{empty}

\begin{document}
\animategraphics[controls]{12}{output-}{1}{144}
\end{document}


Compile to animated SVG with

latex master
dvisvgm --exact --font-format=woff --zoom=-1 master

• We will have to wait for TexLive-2019 to embed from multipage PDF using dvisvgm. – AlexG Jan 3 at 16:38
• @Artificial . I uploaded a new version of animate, 2019/01/23, to CTAN. It allows inclusion of multipage PDF but requires a recent dvisvgm. Thus, for case 6, instead of pdf2ps .., simply run ps2pdf input.ps, and leave framenumbers empty in \animategraphics, to embed all pages in input.pdf. Tested with MikTeX. – AlexG Jan 23 at 19:14