Variables & Substitutions
vars is a special keyword that lets you define variables. These variables can be
referenced with the substitution syntax: ${}.
Variables can be nested
Use . to refer to nested variables.
Variables are scoped
They work just like variable scopes in programming. Substitutions can refer to variables defined in a more outer scope, but not a more inner scope. If a variable appears in two scopes, the one closer to the substitution is used.
Single quotes bypass substitutions
Spread substitutions
If x is a map or an array, ...${x} will spread the contents of x into either a map
or an array.
Configuration variables
Some configurations can be made directly in vars instead of using flags or environment
variables.
This is equivalent to calling the following with no vars:
For top-level settings such as theme-id and pad, flags and environment variables take precedence.
In other words, if you call D2_PAD=2 d2 --theme=1 input.d2, it doesn't matter what
theme-id and pad are set to in input.d2's d2-config; it will use the options from
the command.
animate-interval sets the playback interval for all boards.
animate-duration sets the transition time for steps. It also controls pencil shading
and text decorations between layers and scenarios. See the animation configuration.
Use animate-progress and animate-progress-color to control the
playback progress line.
Output scale and SVG appendix
On D2's development branch (master), you can set scale and force-appendix
in the diagram. These source options are available in D2 v0.10.0 and later.
scale: 0.5 renders at half size. Use -1 for automatic sizing, which lets an SVG
fit its container. force-appendix: true adds numbered notes for links and tooltips
to SVG exports, including animated boards. PNG exports already include the notes.
To export the same diagram at its natural size without the SVG appendix, run
d2 --scale=1 --force-appendix=false input.d2 output.svg.