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:
TexPlain (non-LaTeX) text, rendered as one packed batch of cubic bezier glyphs.
Use
Texfor mathematics and this for prose. Index it to get individual glyphs (text[0]), and seewrite()for the hand-written entrance.When Pango is available (manim’s optional
Textsupport), the styling arguments –font,weight,slant,line_spacing,disable_ligatures, and the span-levelcolor_map/font_map/slant_map/weight_map/gradient_map/gradient– are forwarded to the Pango renderer and fully affect the glyphs. Color values incolor_map/gradient_map/gradientmay be algan colors (glow and opacity are preserved), hex strings, or named manim colors.weightaccepts Pango weight names ("THIN","LIGHT","MEDIUM","SEMIBOLD","BOLD","HEAVY", …),slantaccepts"NORMAL","ITALIC","OBLIQUE"; both are matched case-insensitively. Note acolor_mapvalue 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 totab_widthspaces.fill_opacity – Opacity of the glyph interiors, 0 for invisible and 1 for solid. Manim’s spelling of Algan’s
opacity. Defaults to1.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.Textis the exact-parity spelling. Defaults to0, no outline.color – Color of the glyphs, and of their outline if one is drawn. Accepts an Algan
Color, a named constant such asBLUE, or anythingColor()accepts. Defaults toNone, 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 to48, so plainTextcomes out twice the size of plainTex.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 withslant, 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
textexpands to. Defaults to4.warn_missing_font – Whether to log a warning when
fontis not installed. Defaults toTrue.height – Scale the finished text uniformly so it is this tall, in world units. Defaults to
None, its natural size forfont_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 toNone.center – Whether to move the finished text to the world origin. Defaults to
True; passFalseto keep the positionlocationgave 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 toFalse.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– notablylocation,stroke_color,sceneandadd_to_scene.
Examples
Plain prose, and the same words with one span colored:
Example: Example1Text ¶
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 this plain text with Manim's default Pango outline style.
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).- write(*args, **kwargs)[source]¶
Write this plain text with Manim’s default Pango outline style.
Manim’s
Textkeeps a white stroke color when only its fill color is changed, so a stroke-free colored word is first traced in white.Texinstead traces in its own color. An explicit Alganstroke_colorkeeps that custom outline behavior.Spawn the text without its ordinary entrance first:
Text(...).spawn(False).write().