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: ManimCompatMob

Display (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. For Text("Hello world"), index 5 refers 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 original text argument, whitespace included. For Text("Hello World"), t2c={'[3:7]': RED} colors "l", "o", "W" (the space at index 5 falls in range but has nothing to color), whereas my_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/t2g by 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:

Text

Tests

Check that the creation of Text works:

>>> Text('The horse does not eat cucumber salad.')
Text('The horse does not eat cucumber salad.')

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).