| 1 |
# svg-animate |
| 2 |
|
| 3 |
**svg-animate** turns your TikZ diagrams into step-by-step animations that |
| 4 |
run natively in any web browser — no JavaScript, no plugins, no PDF viewer |
| 5 |
required. |
| 6 |
|
| 7 |
Write your diagram once. Get two outputs from the same source file: |
| 8 |
|
| 9 |
- an **animated SVG** for the web, embedded slides, or GitHub README previews |
| 10 |
- a **static PDF** for print, with all steps stacked or collapsed to a single |
| 11 |
clean frame |
| 12 |
|
| 13 |
The animation model maps directly onto the way you already think about |
| 14 |
progressive diagram reveals: |
| 15 |
|
| 16 |
- **`\begin{animate}`** — wraps your TikZ picture |
| 17 |
- **`\reveal{...}`** — marks what appears at the current step |
| 18 |
- **`\animstep`** — advances to the next step |
| 19 |
|
| 20 |
That is all you need for a working animation. Fine-grained control is there |
| 21 |
when you need it: per-step durations, multi-step and range visibility, |
| 22 |
blinking elements, one-shot or looping playback, and a `\noanimate` fallback |
| 23 |
that controls what a PDF reader shows after the animation ends. |
| 24 |
|
| 25 |
A LaTeX package for producing **animated SVG diagrams** with TikZ. |
| 26 |
|
| 27 |
The animation model is simple: content is divided into discrete *steps*, and |
| 28 |
only one step is fully visible at a time — like frames in a film. Opacity |
| 29 |
transitions are instantaneous (no cross-fades), implemented as SMIL keyframes |
| 30 |
in the SVG output. |
| 31 |
|
| 32 |
## Quick start |
| 33 |
|
| 34 |
```latex |
| 35 |
\documentclass{standalone} |
| 36 |
\usepackage{svg-animate} |
| 37 |
|
| 38 |
\begin{document} |
| 39 |
\begin{tikzpicture} |
| 40 |
\begin{animate}[duration=1] |
| 41 |
\reveal{\node at (0,0) {Step 1};} |
| 42 |
\animstep |
| 43 |
\reveal{\node at (0,0) {Step 2};} |
| 44 |
\animstep |
| 45 |
\reveal{\node at (0,0) {Step 3};} |
| 46 |
\end{animate} |
| 47 |
\end{tikzpicture} |
| 48 |
\end{document} |
| 49 |
``` |
| 50 |
|
| 51 |
## Compilation |
| 52 |
|
| 53 |
```bash |
| 54 |
# Animated SVG |
| 55 |
latex diagram.tex && latex diagram.tex |
| 56 |
dvisvgm --font-format=woff2 --optimize=all --bbox=min diagram.dvi -o diagram.svg |
| 57 |
|
| 58 |
# Static PDF (animations ignored) |
| 59 |
xelatex diagram.tex |
| 60 |
``` |
| 61 |
|
| 62 |
### Embedding bitmap icons |
| 63 |
|
| 64 |
If your diagram includes PNG or JPEG images (e.g. via `\includegraphics`), add |
| 65 |
`--embed-bitmaps` to make the SVG self-contained — images are inlined as base64 |
| 66 |
data URIs instead of external file references: |
| 67 |
|
| 68 |
```bash |
| 69 |
dvisvgm --font-format=woff2 --optimize=all --bbox=min --embed-bitmaps diagram.dvi |
| 70 |
``` |
| 71 |
|
| 72 |
> **Note:** `svg-animate` overrides the graphicx dvisvgm driver's |
| 73 |
> `\Ginclude@bitmap` so that bitmaps are referenced via |
| 74 |
> `\special{dvisvgm:img}`, the only special type that `--embed-bitmaps` |
| 75 |
> actually processes. The stock driver uses `\special{dvisvgm:raw}`, which |
| 76 |
> `--embed-bitmaps` silently ignores. |
| 77 |
> |
| 78 |
> **Requires dvisvgm ≥ 3.4.** Support for `--embed-bitmaps` on `dvisvgm:img` |
| 79 |
> specials was added in dvisvgm 3.4 (2024-07-24). With earlier versions, |
| 80 |
> bitmaps remain as external file references regardless of `--embed-bitmaps`. |
| 81 |
|
| 82 |
Or simply run `make` inside the package directory to build `svg-animate-example.svg` and |
| 83 |
`doc.pdf`. |
| 84 |
|
| 85 |
## Example — traffic light |
| 86 |
|
| 87 |
The included `svg-animate-example.tex` animates a traffic light. Each |
| 88 |
coloured circle is its own step; the amber light uses a shorter `duration`. |
| 89 |
|
| 90 |
 |
| 91 |
|
| 92 |
> Open `svg-animate-example.svg` directly in a browser to see the animation. |
| 93 |
> GitHub's Markdown renderer may display it as a static image. |
| 94 |
|
| 95 |
## Feature showcase |
| 96 |
|
| 97 |
The `svg-animate-test.tex` file exercises the main features side by side: |
| 98 |
|
| 99 |
 |
| 100 |
|
| 101 |
| Column | Setting | What it shows | |
| 102 |
|---|---|---| |
| 103 |
| **loop=true** | default | loops indefinitely | |
| 104 |
| **loop=false** | `loop=false` + `\noanimate` | plays once, reverts to a static resting state | |
| 105 |
| **static** | `inactive opacity=1` | all steps visible simultaneously | |
| 106 |
|
| 107 |
Labels beside each light illustrate: |
| 108 |
|
| 109 |
- **fr. 1** — standard `\reveal`, active only in step 1 |
| 110 |
- **fr. 2+4** / **fr. 3+4** — `step={2,4}` / `step={3,4}`, active in multiple non-consecutive steps |
| 111 |
- **fr. 3 — blink** — `blink=0.3`, flashes during step 3; hidden between steps (default `blink off opacity=0`) |
| 112 |
- **fr. 3 — dimmed blink** — `blink=0.3, inactive opacity=0, blink off opacity=0.25`, hidden between steps; blinks between 1 and 0.25 during step 3 |
| 113 |
- **step={1-3}** — range syntax, active in steps 1 through 3 |
| 114 |
- **step={1,2,3,4}** — always visible, active in every step |
| 115 |
|
| 116 |
## Static PDF output |
| 117 |
|
| 118 |
In PDF mode (`xelatex`, `pdflatex`) the package detects the output format and |
| 119 |
adapts automatically: |
| 120 |
|
| 121 |
- **No `\noanimate`** — `\reveal` elements are drawn at full opacity |
| 122 |
simultaneously (all steps stacked), which is useful for a quick overview. |
| 123 |
- **`\noanimate{content}` present** — `\reveal` elements are suppressed and |
| 124 |
only the `\noanimate` content is drawn, giving a single clean static frame. |
| 125 |
- **`\reveal[noanimate]{content}`** — forces this specific element to render |
| 126 |
in PDF even when `\noanimate` is active in the same environment. |
| 127 |
|
| 128 |
`\noanimate` is completely ignored in SVG mode. |
| 129 |
|
| 130 |
## Key interface |
| 131 |
|
| 132 |
| Level | Syntax | Scope | |
| 133 |
|---|---|---| |
| 134 |
| Global | `\tikzset{/anim/duration=2}` | all diagrams | |
| 135 |
| Environment | `\begin{animate}[duration=1, inactive opacity=0]` | this environment | |
| 136 |
| Step | `\animstep[duration=0.5]` | following step | |
| 137 |
| Element | `\reveal[inactive opacity=0.2]{...}` | this element | |
| 138 |
| Static fallback | `\noanimate{...}` | PDF only, SVG ignored | |
| 139 |
|
| 140 |
### `/anim/.cd` keys |
| 141 |
|
| 142 |
| Key | Default | Description | |
| 143 |
|---|---|---| |
| 144 |
| `duration` | `2` | seconds per step | |
| 145 |
| `active opacity` | `1` | opacity when step is active | |
| 146 |
| `inactive opacity` | `0` | opacity when step is inactive (`0`=hidden, `>0`=dimmed) | |
| 147 |
| `loop` | `true` | `false` = play once and freeze on last frame | |
| 148 |
| `noanimate` | — | force this `\reveal` to render in PDF even when `\noanimate` is present | |
| 149 |
| `step=<spec>` | — | show element during specific steps (see below) | |
| 150 |
| `blink=<seconds>` | — | blink at given period during the active step (see below) | |
| 151 |
| `blink on opacity` | `1` | opacity during blink "on" half-periods within the active step | |
| 152 |
| `blink off opacity` | `0` | opacity during blink "off" half-periods within the active step (between steps the element uses `inactive opacity`) | |
| 153 |
| `static` | — | render all `\reveal` at full opacity (no animation); shorthand for the "show all steps simultaneously" idiom | |
| 154 |
|
| 155 |
### One-shot animation with `loop=false` |
| 156 |
|
| 157 |
By default animations loop indefinitely. Set `loop=false` to play through |
| 158 |
all steps once and freeze on the last frame: |
| 159 |
|
| 160 |
```latex |
| 161 |
\begin{animate}[duration=1, loop=false] |
| 162 |
\reveal{\node {Step 1};} |
| 163 |
\animstep |
| 164 |
\reveal{\node {Step 2};} |
| 165 |
\animstep |
| 166 |
\reveal{\node {Step 3};} |
| 167 |
\end{animate} |
| 168 |
``` |
| 169 |
|
| 170 |
The global default can be changed with `\tikzset{/anim/loop=false}`. |
| 171 |
|
| 172 |
When the animation ends, the SVG browser reverts each element to its base |
| 173 |
opacity (fully visible). If a `\noanimate` fallback is present it therefore |
| 174 |
becomes visible at that point, giving the diagram a natural static resting |
| 175 |
state after the animation completes. |
| 176 |
|
| 177 |
### Multi-step visibility with `step=` |
| 178 |
|
| 179 |
By default `\reveal` makes an element visible only during the **current step**. |
| 180 |
The `step=` key overrides this: the element becomes visible during every step |
| 181 |
in the specification, regardless of where `\reveal` is placed. |
| 182 |
|
| 183 |
```latex |
| 184 |
\begin{animate}[inactive opacity=0.08] |
| 185 |
\reveal[step={1,3}]{\node[red] at (4,1) {visible in steps 1 and 3};} |
| 186 |
\reveal[step=2-4]{ \node[blue] at (4,0) {visible in steps 2 through 4};} |
| 187 |
\reveal[step={1,3-5}]{\node at (4,-1) {steps 1, 3, 4, 5};} |
| 188 |
\end{animate} |
| 189 |
``` |
| 190 |
|
| 191 |
**Syntax:** |
| 192 |
|
| 193 |
- Single step — `step=2` |
| 194 |
- Range — `step=2-5` (steps 2, 3, 4, 5) |
| 195 |
- List — `step={1,3}` (braces required when listing multiple values) |
| 196 |
- Mix — `step={1,3-5}` (braces required) |
| 197 |
|
| 198 |
Consecutive steps in the specification are automatically merged into one |
| 199 |
animation window (no redundant keyframe at the shared boundary). |
| 200 |
|
| 201 |
### Blinking elements with `blink=` |
| 202 |
|
| 203 |
The `blink=` key makes an element flash on and off during its active step. |
| 204 |
The value is the **full blink period** in seconds: the element is visible for |
| 205 |
`period/2` seconds, hidden for `period/2` seconds, and repeats. |
| 206 |
|
| 207 |
```latex |
| 208 |
\begin{animate}[duration=2, inactive opacity=0.15] |
| 209 |
\reveal{\node at (0,1) {Step 1 — static};} |
| 210 |
\animstep |
| 211 |
\reveal[blink=0.4]{\node[fill=yellow] at (0,0) {Step 2 — blinks};} |
| 212 |
\animstep |
| 213 |
\reveal{\node at (0,-1) {Step 3 — static};} |
| 214 |
\end{animate} |
| 215 |
``` |
| 216 |
|
| 217 |
If the step duration is not an exact multiple of `period/2`, the last |
| 218 |
partial half-period is shown up to the step boundary. |
| 219 |
|
| 220 |
`blink=` and `step=` are mutually exclusive; when both are given, `blink=` |
| 221 |
takes priority. |
| 222 |
|
| 223 |
The blink amplitude is controlled via `blink on opacity` (default `1`) and |
| 224 |
`blink off opacity` (default `0`). These keys govern **only** the intra-step |
| 225 |
oscillation; between steps the element uses `inactive opacity` as normal. |
| 226 |
|
| 227 |
To hide a blink element between steps, set `inactive opacity=0` explicitly. |
| 228 |
Because the static column now uses `\begin{animate}[static]`, this does not |
| 229 |
affect the static display: |
| 230 |
|
| 231 |
```latex |
| 232 |
%% Hidden between steps; blinks between 1 and 0.25 during step 2. |
| 233 |
\reveal[blink=0.4, inactive opacity=0, blink off opacity=0.25]{ |
| 234 |
\node[fill=yellow] at (0,0) {Step 2}; |
| 235 |
} |
| 236 |
``` |
| 237 |
|
| 238 |
### Static display with `static` |
| 239 |
|
| 240 |
To render all steps simultaneously at full opacity (for a printed handout or |
| 241 |
overview), use the `static` key on the `animate` environment: |
| 242 |
|
| 243 |
```latex |
| 244 |
\begin{animate}[static] |
| 245 |
\stepOne \animstep \stepTwo \animstep \stepThree |
| 246 |
\end{animate} |
| 247 |
``` |
| 248 |
|
| 249 |
All `\reveal` elements are drawn at their natural opacity regardless of |
| 250 |
`inactive opacity`, `blink on/off opacity`, or any other per-element setting. |
| 251 |
This is cleaner than setting four opacity keys to `1`. |
| 252 |
|
| 253 |
## Installation |
| 254 |
|
| 255 |
Copy the `svg-animate` directory into a location where TeX can find it. |
| 256 |
Common user-local locations (no root access required): |
| 257 |
|
| 258 |
- `$TEXMFHOME/tex/latex/` |
| 259 |
- `$TEXHOME/tex/latex/` |
| 260 |
- `~/texmf/tex/latex/` (typical Linux default) |
| 261 |
- `~/Library/texmf/tex/latex/` (typical macOS default) |
| 262 |
|
| 263 |
Alternatively, point `TEXINPUTS` at the directory containing `svg-animate.sty` |
| 264 |
before compiling: |
| 265 |
|
| 266 |
```bash |
| 267 |
TEXINPUTS="path/to/svg-animate//:$TEXINPUTS" latex diagram.tex |
| 268 |
``` |
| 269 |
|
| 270 |
The trailing `//` tells TeX to search subdirectories recursively. |
| 271 |
|
| 272 |
## Requirements |
| 273 |
|
| 274 |
- PGF/TikZ ≥ 3.1.9 (for `\usetikzlibrary{animations}`) |
| 275 |
- `dvisvgm` ≥ 2.9 for SVG output |
| 276 |
- `dvisvgm` ≥ 3.4 for bitmap embedding (`--embed-bitmaps` with `dvisvgm:img` |
| 277 |
was added in 3.4; earlier versions leave bitmaps as external file references) |
| 278 |
- Any modern LaTeX distribution (TeX Live 2022+, MiKTeX 22+) |
| 279 |
|
| 280 |
## Documentation |
| 281 |
|
| 282 |
```bash |
| 283 |
make doc.pdf |
| 284 |
``` |
| 285 |
|
| 286 |
Full documentation with key reference, examples, and change log: `svg-animate.pdf`. |
| 287 |
|
| 288 |
## Copyright |
| 289 |
|
| 290 |
`svg-animate` is copyright 2026 Sébastien Gross and distributed under |
| 291 |
the terms of the GNU Affero General Public License v3.0 or later. |