MathTex

Qualified name: algan.mobs.manim\_compat.MathTex

class MathTex(*tex_strings, arg_separator=' ', substrings_to_isolate=None, tex_to_color_map=None, tex_environment='align*', **kwargs)

Bases: ManimCompatMob

A LaTeX string typeset in math mode, wrapping Manim’s MathTex.

Manim compiles the formula and builds its glyph outlines; Algan converts those to cubic bezier circuits and animates them on its own timeline. Manim’s own arguments work as written – tex_to_color_map and substrings_to_isolate included – and Manim methods Algan does not implement are delegated to the backing object.

Reach for Algan’s Tex when you are not porting a script. The two produce the same outlines (MathTex("x^2") matches Tex("x^2", font_size=48), because Algan’s Tex also builds at Manim’s 48 and then scales), but this one is a single Mob with no per-glyph views: formula[0] raises TypeError, and character indexing, get_segment() and write() all live on Tex instead.

Animation

Constructing one records nothing: LaTeX runs immediately and the Mob joins the active Scene unspawned. Call spawn() to make it appear. Everything after that – formula.color = BLUE, a move, a delegated Manim edit – is recorded on the timeline like any other Mob’s, over the current context’s runtime.

Parameters:
  • *tex_strings (str) – One or more LaTeX sources, joined by arg_separator and compiled as a single document.

  • arg_separator (str) – Inserted between consecutive tex_strings in the compiled source. Defaults to " ", one space.

  • substrings_to_isolate (Iterable[str] | None) – Substrings to split the source on before compiling, so each ends up as its own piece of the result. Defaults to None, meaning no extra splitting beyond what the separate tex_strings already give.

  • tex_to_color_map (dict[str, ParsableManimColor] | None) – Maps a substring of the source to the color its glyphs take; the substring is isolated for you. Accepts Manim colors, hex strings, or Algan Color values – an Algan color is converted to hex on the way through Manim, so its glow and opacity are dropped and have to be set on the Mob afterwards. Defaults to None, one color throughout.

  • tex_environment (str | None) – Name of the LaTeX environment to typeset in, such as "gather*". Defaults to "align*".

  • **kwargs (Any) – Manim’s remaining MathTex arguments – notably font_size (defaults to 48), color, tex_template, stroke_width and should_center – plus the Algan-only scene, add_to_scene, glow and glow_radius.

Raises:

ValueError – If LaTeX fails to compile the source. The most common cause is tex_to_color_map or substrings_to_isolate: they split the source on the literal substring, so a key that also occurs inside a control sequence or a brace group cuts it in half. Coloring "n" in a formula containing \infty is enough to do it. Pick a key that stands alone, or pass the pieces as separate tex_strings.

See also

Tex

Algan’s own LaTeX Mob, with per-glyph views, segments and the hand-writing animation.

Examples

A formula, and one with two symbols picked out by tex_to_color_map:

Example: Example1MathTex

../_images/Example1MathTex-1.png
from algan import *

MathTex(r"\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}",
        font_size=36).move(UP * 0.5).spawn()
MathTex(r"a^2 + b^2 = c^2", font_size=36,
        tex_to_color_map={"a": BLUE, "b": YELLOW}).move(DOWN * 0.5).spawn()

Scene.save_video()

Methods

Attributes

animation_manager

This mob's scene-owned animation manager.

basis

The Mob's orientation and scale, as a flattened 3x3 matrix of shape (*, 9).

casts_shadows

Whether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.

children

The Mobs attached below this one, in attachment order.

closed_shell

Whether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.

draws_descendants

Whether get_render_primitives returns geometry belonging to this Mob's DESCENDANTS as well as its own.

forward

Get the direction the Mob is facing.

lifespan

This mob's [spawn, despawn) interval on its Scene timeline (a Lifespan).

location

The Mob's position in world space, shape (*, 3).

normalized_basis

The Mob's orientation with scale divided out, shape (*, 9).

parents

The Mobs this one is attached to, in attachment order.

receives_shadows

Whether this Mob's surfaces are darkened by shadows cast onto them.

right

Get the Mob's own rightward direction.

scale_coefficient

The Mob's scale along its own right, up and forward axes, shape (*, 3).

stroke_color

The color of the circuit's border stroke.

two_sided

Whether this Mob's geometry should be lit from whichever side the ray arrives on.

up

Get the Mob's own upward direction.

x

The Mob's x coordinate in world units, shape (*, 1).

xy

The Mob's x and y coordinates in world units, shape (*, 2).

y

The Mob's y coordinate in world units, shape (*, 1).

z

The Mob's z coordinate in world units, shape (*, 1).

z_index

Which of two exactly coplanar circuits draws in front (higher wins).