MathTypst

Qualified name: manim.mobject.text.typst\_mobject.MathTypst

class MathTypst(math_expression, **kwargs)[source]

Bases: Typst

Convenience wrapper: wraps the input in Typst math delimiters.

The expression is rendered as a display-level equation ($ ... $ with surrounding spaces).

Supports the {{ ... }} double-brace notation for grouping sub-expressions. Each {{ content }} is wrapped in a labeled manimgrp call so that the resulting SVG contains identifiable groups accessible via select().

Groups can optionally be given explicit labels: {{ content : label }}. Without a label, groups are auto-numbered (_grp-0, _grp-1, …).

Parameters:
  • math_expression (str) – Typst math-mode content without the $ ... $ delimiters. May contain {{ ... }} groups.

  • **kwargs (Any) – Forwarded to Typst.

Examples

Example: DisplayMath

../_images/DisplayMath-1.png
from manim import *

class DisplayMath(Scene):
    def construct(self):
        eq = MathTypst(r"sum_(k=0)^n k = (n(n+1)) / 2")
        self.add(eq)
class DisplayMath(Scene):
    def construct(self):
        eq = MathTypst(r"sum_(k=0)^n k = (n(n+1)) / 2")
        self.add(eq)

References: MathTypst

Example: GroupedMath

../_images/GroupedMath-1.png
from manim import *

class GroupedMath(Scene):
    def construct(self):
        eq = MathTypst("{{ a^2 + b^2 : lhs }} = {{ c^2 }}")
        eq.select("lhs").set_color(RED) # "a^2 + b^2"
        eq.select(0).set_color(BLUE)    # "c^2" (auto-numbered: "grp-0")
        self.add(eq)
class GroupedMath(Scene):
    def construct(self):
        eq = MathTypst("{{ a^2 + b^2 : lhs }} = {{ c^2 }}")
        eq.select("lhs").set_color(RED) # "a^2 + b^2"
        eq.select(0).set_color(BLUE)    # "c^2" (auto-numbered: "grp-0")
        self.add(eq)

References: MathTypst select()

Methods

Attributes

always

Call a method on a mobject every frame.

animate

Used to animate the application of any method of self.

animation_overrides

baseline_frames

Current Typst baseline frames for all tracked leaf submobjects.

color

depth

The depth of the mobject.

fill_color

If there are multiple colors (for gradient) this returns the first one

font_size

The font size of the Typst mobject.

hash_seed

Include baseline tracking in the SVG cache key.

height

The height of the mobject.

n_points_per_curve

sheen_factor

stroke_color

width

The width of the mobject.

target

original_id

_original__init__(math_expression, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • math_expression (str)

  • kwargs (Any)

static _preprocess_groups(math_expr)[source]

Replace {{ ... }} groups with manimgrp(...) calls.

Parameters:

math_expr (str) – The raw math expression (without $ ... $ delimiters).

Returns:

The processed expression and an ordered list of group labels.

Return type:

tuple[str, list[str]]