Text¶
Qualified name: algan.mobs.manim\_compat.Text
- class Text(text, fill_opacity=1.0, stroke_width=0, color=None, font_size=48, line_spacing=-1, font='', slant='NORMAL', weight='NORMAL', t2c=None, t2f=None, t2g=None, t2s=None, t2w=None, gradient=None, tab_width=4, warn_missing_font=True, height=None, width=None, should_center=True, disable_ligatures=False, use_svg_cache=False, **kwargs)¶
Bases:
ManimCompatMobDisplay (non-LaTeX) text rendered using Pango.
Text objects behave like a
VGroup-like iterable of all characters in the given text. In particular, slicing is possible.Warning
Whitespace and newline characters are stripped internally and never become their own submobject (there is nothing to render for them), so slicing indices are interpreted differently depending on where they are used, and the two conventions disagree with each other:
Slicing the object itself (
my_text[3:5]) indexes into the rendered characters, i.e. the text with whitespace removed. ForText("Hello world"), index5refers to"w", not to the space between the two words.The slice syntax in
t2c/t2s/t2w/t2f/t2g(e.g.t2c={'[3:7]': RED}) indexes into the originaltextargument, whitespace included. ForText("Hello World"),t2c={'[3:7]': RED}colors"l","o","W"(the space at index 5 falls in range but has nothing to color), whereasmy_text[3:7]selects the 4 rendered characters"loWo".
When the substring you want to select is known in advance, prefer keying
t2c/t2s/t2w/t2f/t2gby that substring directly (e.g.t2c={"world": RED}), which matches by text search instead of by index and is unaffected by this quirk.- Parameters:
text (str) – The text that needs to be created as a mobject.
font (str) – The font family to be used to render the text. This is either a system font or one loaded with register_font(). Note that font family names may be different across operating systems.
warn_missing_font (bool) – If True (default), Manim will issue a warning if the font does not exist in the (case-sensitive) list of fonts returned from manimpango.list_fonts().
fill_opacity (float)
stroke_width (float)
color (ParsableManimColor | None)
font_size (float)
line_spacing (float)
slant (str)
weight (str)
t2c (dict[str, str] | None)
t2f (dict[str, str] | None)
t2g (dict[str, Iterable[ParsableManimColor]] | None)
t2s (dict[str, str] | None)
t2w (dict[str, str] | None)
gradient (Iterable[ParsableManimColor] | None)
tab_width (int)
height (float | None)
width (float | None)
should_center (bool)
disable_ligatures (bool)
use_svg_cache (bool)
kwargs (Any)
- Returns:
The mobject-like
VGroup.- Return type:
Tests
Check that the creation of
Textworks:>>> Text('The horse does not eat cucumber salad.') Text('The horse does not eat cucumber salad.')
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).