SVG Template (Directive)

  • Directive Type: “image”
  • Doctree Elements: figure, image, caption, legend
  • Directive Arguments: One, required (image URI).
  • Directive Options: Possible.
  • Directive Content: Interpreted as the figure caption and an optional legend.

A “svgt” is a figure ( rendered from a svg replaced all ${variables} with a given values.

You can create the svg with any software (like inkscape) and put inside text variables formated like ${variables} and it will replaced from the argument vars

NOTE: The directive depends on inkscape (

.. svgt:: /path/to/svg_file.svg

    :vars: {"var_name0": "var_value0,
            "var_name1": "var_value1",
            "var_nameN": "var_valueN"}
    :dpi: 32
    :inkscape_dir: /path/to/inkscape/directory/

    This is the caption of the rendered svg (a simple paragraph).

    The legend consists of all elements **after** the caption.  In this
    case, the legend consists of this paragraph and the following

       | Symbol                | Meaning               |
       | .. image:: tent.png   | Campground            |
       | .. image:: waves.png  | Lake                  |
       | .. image:: peak.png   | Mountain              |

There must be blank lines before the caption paragraph and before the legend. To specify a legend without a caption, use an empty comment (”..”) in place of the caption.

The “svgt” directive supports all of the options of the “figure” directive are passed on to the contained created figure.

In addition, the following options are recognized:

vars: json string
An json string containing all the variable values to be replaced in the svg.
dpi: non-negative int
The dpi of the image generated from svg (default: 72).
inkscape_dir: path
The directory where the binary of inkscape lives (default: “”).
list_vars_and_exit: flag
If you add this argument will be printed on standard output all the variables that are in the svg.
class svgt.SVGTemplate(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]

The svgt directive


SVG Template Sphinx Integration

This directive add a config value named tempdir (defaul: _temp) when the images are rendered.


With this images

  • _images/temp.png
  • _images/troll.png

And this code

.. svgt:: images/temp.svg
    :vars: {"name": "Render with svgt", "url": "images/troll.png"}

    This is an example of render

Generate this:


This is an example of render