manim_directive

A directive for including Manim videos in a Sphinx document

When rendering the HTML documentation, the .. manim:: directive implemented here allows to include rendered videos.

Its basic usage that allows processing inline content looks as follows:

.. manim:: MyScene

    class MyScene(Scene):
        def construct(self):
            ...

It is required to pass the name of the class representing the scene to be rendered to the directive.

As a second application, the directive can also be used to render scenes that are defined within doctests, for example:

.. manim:: DirectiveDoctestExample
    :ref_classes: Dot

    >>> dot = Dot(color=RED)
    >>> dot.color
    <Color #fc6255>
    >>> class DirectiveDoctestExample(Scene):
    ...     def construct(self):
    ...         self.play(Create(dot))

Options

Options can be passed as follows:

.. manim:: <Class name>
    :<option name>: <value>

The following configuration options are supported by the directive:

hide_source

If this flag is present without argument, the source code is not displayed above the rendered video.

quality{‘low’, ‘medium’, ‘high’, ‘fourk’}

Controls render quality of the video, in analogy to the corresponding command line flags.

save_as_gif

If this flag is present without argument, the scene is rendered as a gif.

save_last_frame

If this flag is present without argument, an image representing the last frame of the scene will be rendered and displayed, instead of a video.

ref_classes

A list of classes, separated by spaces, that is rendered in a reference block after the source code.

ref_functions

A list of functions, separated by spaces, that is rendered in a reference block after the source code.

ref_methods

A list of methods, separated by spaces, that is rendered in a reference block after the source code.

Classes

ManimDirective

The manim directive, rendering videos while building the documentation.

skip_manim_node

Functions

depart(self, node)[source]
process_name_list(option_input, reference_type)[source]

Reformats a string of space separated class names as a list of strings containing valid Sphinx references.

Tests

>>> process_name_list("Tex TexTemplate", "class")
[":class:`~.Tex`", ":class:`~.TexTemplate`"]
>>> process_name_list("Scene.play Mobject.rotate", "func")
[":func:`~.Scene.play`", ":func:`~.Mobject.rotate`"]
Parameters
  • option_input (str) –

  • reference_type (str) –

Return type

List[str]

setup(app)[source]
visit(self, node, name='')[source]