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:
ManimCompatMobA 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_mapandsubstrings_to_isolateincluded – and Manim methods Algan does not implement are delegated to the backing object.Reach for Algan’s
Texwhen you are not porting a script. The two produce the same outlines (MathTex("x^2")matchesTex("x^2", font_size=48), because Algan’sTexalso builds at Manim’s 48 and then scales), but this one is a single Mob with no per-glyph views:formula[0]raisesTypeError, and character indexing,get_segment()andwrite()all live onTexinstead.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_separatorand compiled as a single document.arg_separator (str) – Inserted between consecutive
tex_stringsin 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 separatetex_stringsalready 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
Colorvalues – 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 toNone, 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
MathTexarguments – notablyfont_size(defaults to48),color,tex_template,stroke_widthandshould_center– plus the Algan-onlyscene,add_to_scene,glowandglow_radius.
- Raises:
ValueError – If LaTeX fails to compile the source. The most common cause is
tex_to_color_maporsubstrings_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\inftyis enough to do it. Pick a key that stands alone, or pass the pieces as separatetex_strings.
See also
TexAlgan’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 ¶
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_managerThis mob's scene-owned animation manager.
basisThe Mob's orientation and scale, as a flattened 3x3 matrix of shape
(*, 9).casts_shadowsWhether this Mob's geometry blocks light on its way from a light source to another surface -- whether it casts a shadow.
childrenThe Mobs attached below this one, in attachment order.
closed_shellWhether this Mob's triangles form a CLOSED shell -- every camera ray that enters the geometry crosses a second time on its way out.
draws_descendantsWhether
get_render_primitivesreturns geometry belonging to this Mob's DESCENDANTS as well as its own.forwardGet the direction the Mob is facing.
lifespanThis mob's [spawn, despawn) interval on its Scene timeline (a
Lifespan).locationThe Mob's position in world space, shape
(*, 3).normalized_basisThe Mob's orientation with scale divided out, shape
(*, 9).parentsThe Mobs this one is attached to, in attachment order.
receives_shadowsWhether this Mob's surfaces are darkened by shadows cast onto them.
rightGet the Mob's own rightward direction.
scale_coefficientThe Mob's scale along its own right, up and forward axes, shape
(*, 3).stroke_colorThe color of the circuit's border stroke.
two_sidedWhether this Mob's geometry should be lit from whichever side the ray arrives on.
upGet the Mob's own upward direction.
xThe Mob's x coordinate in world units, shape
(*, 1).xyThe Mob's x and y coordinates in world units, shape
(*, 2).yThe Mob's y coordinate in world units, shape
(*, 1).zThe Mob's z coordinate in world units, shape
(*, 1).z_indexWhich of two exactly coplanar circuits draws in front (higher wins).