Tex¶
Qualified name: algan.mobs.text.Tex
- class Tex(*tex_strings, delimiter=' ', tex_environment=None, font_size=24, latex=True, pango_kwargs=None, pango_color_map=None, sync_stroke_color=True, **kwargs)[source]¶
Bases:
MobLaTeX compiled to one packed batch of cubic bezier glyphs.
The string is typeset in LaTeX’s math mode, so
Tex("x^2")is a squared x rather than the three literal characters. Passlatex=Falsefor prose, or useText, which is this class wired to a Pango font renderer instead.The glyphs are outlines, not bitmaps: the text stays sharp at any scale and morphs into other 2-D shapes like any other bezier Mob. They arrive as a single packed Mob rather than one Mob per character, which is what makes a long string cheap. Index it to animate one glyph –
equation[3]is a view sharing the batch’s rows, so moving it moves that glyph of the original, and it needs no spawning of its own. Several source strings become several segments, addressable withget_segment(), which is the usual way to highlight one term of an equation.MathTexrenders LaTeX too and is a different object: it is the Manim-compatibility wrapper, for when a ported script needstex_to_color_mapor Manim method delegation. This class is the native one, and the only one with per-glyph indexing,get_segment()andwrite().Animation
Constructing a
Texrecords nothing: LaTeX runs immediately and the Mob joins the active Scene unspawned.spawn()is what plays its entrance –on_create(), a diagonal fade running down and to the right so the words arrive in reading order, lasting 1 second regardless of the enclosing context.Tex(...).spawn(False)skips it, which is whatwrite()wants.- Parameters:
*tex_strings – One or more LaTeX sources. Each becomes a segment retrievable with
get_segment(), and they are compiled as one document so a\leftin one string can close in the next. A single list or tuple is unpacked, and no strings at all gives an emptyTex.delimiter – Inserted between consecutive
tex_stringsin the compiled source (and used to join them whenlatex=False). Defaults to" ", one space.tex_environment – Name of the LaTeX environment to typeset in, such as
"align*"or"gather*". Defaults toNone, meaning Manim’s own default ofalign*.font_size – Glyph size in Manim’s font-size units. The batch is always built at 48 and then scaled by
font_size / 48, so this is a scale factor in disguise:48matches Manim’s default text size and24is half of it. Defaults to24.latex – Whether to typeset through LaTeX.
Falsetreats the strings as plain text and routes them to Manim’s Pango renderer instead – an Algan extension, and howTextis built. Defaults toTrue.pango_kwargs – Styling forwarded to the Pango renderer when
latex=False:font,weight,slant,line_spacing,color_map,gradientand the rest of Manim’sTextarguments. Ignored under LaTeX. Defaults toNone(no styling). PreferText, which exposes these as ordinary named arguments.pango_color_map – Maps the hex strings in
pango_kwargsback to the AlganColorobjects they came from, so glow and opacity survive the round trip through Pango’s SVG output (a hex string cannot carry either). Defaults toNone. Set for you byText.sync_stroke_color – Whether a glyph colored by Pango styling also gets that color on its border. Only has an effect when a border is actually drawn (
stroke_widthabove 0). Defaults toTrue; pass an explicitstroke_colorto keep one outline color across styled glyphs.**kwargs – Passed to
Moband to the packedBezierCircuitCubic– notablycolor(defaults toWHITE),stroke_color,stroke_width(defaults to0, no outline),locationandscene. One extra keyword is consumed here:preamble, a string of LaTeX appended to Manim’s default preamble, for\usepackagelines a formula needs.
- character_mobs¶
Lazy per-glyph views into the packed batch, in typeset order. This is what
tex[i]andwrite()animate.
- tex_strings¶
The source strings as given, after list/tuple unpacking, as a tuple.
- latex¶
Whether this text was typeset by LaTeX rather than by Pango.
Examples
A formula, one segment per term, with the middle term picked out:
Example: Example1Tex ¶
from algan import * equation = Tex(r"e^{i\pi}", "+", "1", "=", "0", font_size=48).spawn() equation.get_segment(2).color = YELLOW Scene.save_video()
latex=Falsefor prose, and a largerfont_size:Example: Example2Tex ¶
from algan import * Tex("Not a formula", latex=False, font_size=48, color=BLUE).spawn() Scene.save_video()
Individual glyphs are views, so animating one animates the original:
Example: Example3Tex ¶
from algan import * word = Tex("ALGAN", font_size=48).spawn() with Sync(): word[0].move(UP * 0.3) word[4].move(DOWN * 0.3) Scene.save_video()
Methods
Morph this text into another Mob, keeping its glyph views usable.
Get one of the text's LaTeX segments as a Mob.
Play the text's entrance: a fade that sweeps across the glyphs.
Play the text's exit: a fade that sweeps across the glyphs.
Animate this text appearing as if it were being hand-written.
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).triangulatedtwo_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).- become(other_mob, *args, **kwargs)[source]¶
Morph this text into another Mob, keeping its glyph views usable.
As
become(), with one addition: because a morph can expand the packed glyph batch, the per-character views are rebuilt against the result, so indexing (text[0]) still works afterwards.Animation
Recorded as an animation over the current context’s runtime (1 second by default).
- Parameters:
other_mob – The Mob to morph into. Text-to-text and text-to-bezier morphs preserve the tightest correspondence; other primitive families use geometric conversion or a dissolve according to
strategy.*args – Passed to
become()– notablyminimize_movement=True, which pairs each glyph fragment with its nearest counterpart and is usually what you want for text.**kwargs – Passed to
become()– notablyminimize_movement=True, which pairs each glyph fragment with its nearest counterpart and is usually what you want for text.
- Returns:
The morphed Mob. With the default
detach_history=Truethis can be a different object from the one you called the method on, so use the return value afterwards. Character views are rebuilt when the result is still text.- Return type:
- get_segment(index)[source]¶
Get one of the text’s LaTeX segments as a Mob.
Segments are the pieces the text was constructed from, so a
Texbuilt from several strings can have each one animated separately – the usual way to highlight one term of an equation.- Parameters:
index (int) – Index of the segment.
- Returns:
A Group of the glyphs in that segment, sharing data with this text.
- Return type:
- on_create()[source]¶
Play the text’s entrance: a fade that sweeps across the glyphs.
Instead of the plain fade a
Mobuses, text fades in as a diagonal wave running down and to the right, so the words appear to arrive in reading order.Animation
Recorded as an animation lasting 1 second, regardless of the enclosing context’s runtime.
- Returns:
This text, so calls can be chained.
- Return type:
- on_destroy()[source]¶
Play the text’s exit: a fade that sweeps across the glyphs.
The mirror of
on_create()– the glyphs fade out as a diagonal wave rather than all at once.Animation
Recorded as an animation over the current context’s runtime (1 second by default). The despawn itself is recorded at the end of the wave, so no glyph disappears before the wave reaches it.
- Returns:
This text, so calls can be chained.
- Return type:
- write(*args, **kwargs)[source]¶
Animate this text appearing as if it were being hand-written.
Each glyph’s outline is traced and then filled, one glyph after another. This is
DrawBorderThenFill()applied to this text’s glyphs.Animation
Recorded as an animation. Its runtime comes from
runtimeandlag_ratiorather than the enclosing context, so a long string takes longer to write unless you setruntime.- Parameters:
*args – Passed to
DrawBorderThenFill()**kwargs – Passed to
DrawBorderThenFill()
- Returns:
This text, so calls can be chained.
- Return type:
Examples
Example: Example1TextWrite ¶
from algan import * Text('Hello World!').spawn(False).write() Scene.save_video()