Manim Slides’ IPython magic

Utilities for using Manim Slides with IPython (in particular: Jupyter notebooks).

Note

The current implementation is highly inspired from Manim’s own IPython magics, from v0.17.3.

This magic requires two additional dependencies: manim and IPython. You can install them manually, or with the extra keyword:

pip install "manim-slides[magic]"

Note that you will still need to install Manim’s platform-specific dependencies, see their installation page.

class ManimSlidesMagic(**kwargs: Any)[source]
Parameters:

shell (InteractiveShell)

manim_slides(line: str, cell: str | None = None, local_ns: dict[str, Any] | None = None) None[source]

Render Manim Slides contained in IPython cells. Works as a line or cell magic.

Note

This magic works pretty much like the one from Manim, except that it will render Manim Slides using RevealJS. For passing arguments to Manim Slides’ convert module, use -manim-slides key=value.

Everything that is after --manim-slides will be send to Manim Slides’ command. E.g., use --manim-slides controls=true to display control buttons.

Hint

This line and cell magic works best when used in a JupyterLab environment: while all of the functionality is available for classic Jupyter notebooks as well, it is possible that videos sometimes don’t update on repeated execution of the same cell if the scene name stays the same.

This problem does not occur when using JupyterLab.

Please refer to https://jupyter.org/ for more information about JupyterLab and Jupyter notebooks.

Usage in line mode:

%manim_slides [CLI options] MyAwesomeSlide

Usage in cell mode:

%%manim_slides [CLI options] MyAwesomeSlide

class MyAweseomeSlide(Slide):
    def construct(self):
        ...

Run %manim_slides --help and %manim_slides render --help for possible command line interface options.

Note

The maximal width of the rendered videos that are displayed in the notebook can be configured via the media_width configuration option. The default is set to 25vw, which is 25% of your current viewport width. To allow the output to become as large as possible, set config.media_width = "100%".

The media_embed option will embed the image/video output in the notebook. This is generally undesirable as it makes the notebooks very large, but is required on some platforms (notably Google’s CoLab, where it is automatically enabled unless suppressed by config.embed = False) and needed in cases when the notebook (or converted HTML file) will be moved relative to the video locations. Use-cases include building documentation with Sphinx and JupyterBook. See also the Manim Slides directive for Sphinx.

Examples

First make sure to put from manim_slides import ManimSlidesMagic, or even from manim_slides import * in a cell and evaluate it. Then, a typical Jupyter notebook cell for Manim Slides could look as follows:

%%manim_slides -v WARNING --progress_bar None MySlide --manim-slides controls=true data_uri=true

class MySlide(Slide):
    def construct(self):
        square = Square()
        circle = Circle()

        self.play(Create(square))
        self.next_slide()
        self.play(Transform(square, circle))

Evaluating this cell will render and display the MySlide slide defined in the body of the cell.

Note

In case you want to hide the red box containing the output progress bar, the progress_bar config option should be set to None. This can also be done by passing --progress_bar None as a CLI flag.

Parameters:
Return type:

None