Text

Qualified name: algan.mobs.text.Text

class Text(text, fill_opacity=1.0, stroke_width=0, color=None, font_size=48, line_spacing=None, font='', slant='NORMAL', weight='NORMAL', color_map=None, font_map=None, gradient_map=None, slant_map=None, weight_map=None, gradient=None, tab_width=4, warn_missing_font=True, height=None, width=None, center=True, disable_ligatures=False, use_svg_cache=False, **kwargs)[source]

Bases: Tex

Plain (non-LaTeX) text, rendered as one packed batch of cubic bezier glyphs.

Use Tex for mathematics and this for prose. Index it to get individual glyphs (text[0]), and see write() for the hand-written entrance.

When Pango is available (manim’s optional Text support), the styling arguments – font, weight, slant, line_spacing, disable_ligatures, and the span-level color_map/font_map/slant_map/weight_map/gradient_map/ gradient – are forwarded to the Pango renderer and fully affect the glyphs. Color values in color_map/gradient_map/gradient may be algan colors (glow and opacity are preserved), hex strings, or named manim colors. weight accepts Pango weight names ("THIN", "LIGHT", "MEDIUM", "SEMIBOLD", "BOLD", "HEAVY", …), slant accepts "NORMAL", "ITALIC", "OBLIQUE"; both are matched case-insensitively. Note a color_map value of pure white is indistinguishable from unstyled text and falls back to the base color.

When Pango is unavailable, Algan renders the textual content through LaTeX text mode. Font-family and span-level styling arguments are accepted and retained as metadata, but cannot affect that fallback renderer.

Parameters:
  • text – The text to display. Cast to str, and tabs are expanded to tab_width spaces.

  • fill_opacity – Opacity of the glyph interiors, 0 for invisible and 1 for solid. Manim’s spelling of Algan’s opacity. Defaults to 1.0.

  • stroke_width – Width of the outline drawn around each glyph, in Algan’s stroke units. Manim means twice this by the same number; mn.Text is the exact-parity spelling. Defaults to 0, no outline.

  • color – Color of the glyphs, and of their outline if one is drawn. Accepts an Algan Color, a named constant such as BLUE, or anything Color() accepts. Defaults to None, meaning Algan’s default text color (WHITE).

  • font_size – Glyph size in Manim’s font-size units; the glyphs are built at 48 and scaled by font_size / 48. Defaults to 48, so plain Text comes out twice the size of plain Tex.

  • line_spacing – Distance between baselines of a multi-line string, in Pango’s units. Defaults to None, meaning Pango’s own spacing for the font.

  • font – Font family name, as installed on the system. Defaults to "", meaning Pango’s default family.

  • slant"NORMAL", "ITALIC" or "OBLIQUE", in any case. Defaults to "NORMAL". A name Pango does not know raises, rather than silently rendering in the default face.

  • weight – A Pango weight name – "THIN", "LIGHT", "NORMAL", "MEDIUM", "SEMIBOLD", "BOLD", "HEAVY", and the rest – in any case. Defaults to "NORMAL". As with slant, an unknown name raises.

  • color_map – Maps a substring to the color its glyphs take. Color values may be Algan colors (glow and opacity survive), hex strings, or named Manim colors. A value of pure white is indistinguishable from unstyled text and falls back to the base color. Defaults to None.

  • font_map – Maps a substring to a font family. Defaults to None.

  • gradient_map – Maps a substring to a tuple of colors to fade between across it. Defaults to None.

  • slant_map – Maps a substring to a slant name. Defaults to None.

  • weight_map – Maps a substring to a weight name. Defaults to None.

  • gradient – A tuple of colors faded across the whole string. Defaults to None, one flat color.

  • tab_width – How many spaces a tab in text expands to. Defaults to 4.

  • warn_missing_font – Whether to log a warning when font is not installed. Defaults to True.

  • height – Scale the finished text uniformly so it is this tall, in world units. Defaults to None, its natural size for font_size.

  • width – Scale the finished text uniformly so it is this wide, in world units. Applied after height, so passing both leaves the width matched and the height wherever the aspect ratio puts it. Defaults to None.

  • center – Whether to move the finished text to the world origin. Defaults to True; pass False to keep the position location gave it.

  • disable_ligatures – Whether to render each character separately rather than letting the font combine pairs such as “fi”. Slower, but it makes text[i] line up with the i-th character. Defaults to False.

  • use_svg_cache – Accepted for Manim parity and has no effect: Algan caches the glyph geometry itself, keyed on the source, whatever this is set to. Defaults to False.

  • **kwargs – Passed to Tex – notably location, stroke_color, scene and add_to_scene.

Examples

Plain prose, and the same words with one span colored:

Example: Example1Text

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

Text("Hello, world", font_size=36).move(UP * 0.5).spawn()
Text("Hello, world", font_size=36,
     color_map={"world": BLUE}).move(DOWN * 0.5).spawn()

Scene.save_video()

Methods

write

Write this plain text with Manim's default Pango outline style.

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

triangulated

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

write(*args, **kwargs)[source]

Write this plain text with Manim’s default Pango outline style.

Manim’s Text keeps a white stroke color when only its fill color is changed, so a stroke-free colored word is first traced in white. Tex instead traces in its own color. An explicit Algan stroke_color keeps that custom outline behavior.

Spawn the text without its ordinary entrance first: Text(...).spawn(False).write().