Animation engine for explanatory math videos with programmatic mathematical visualization capabilities
—
ManimGL provides comprehensive text rendering capabilities including plain text, LaTeX mathematical expressions, code highlighting, and markup support. The text system offers precise typographical control and seamless integration with mathematical content for educational animations.
Advanced text rendering with font control, styling, and positioning.
class Text(VMobject):
def __init__(self, text, **kwargs):
"""
Render plain text with advanced typography.
Parameters:
- text: str, text content to render
- font: str, font family name
- font_size: float, text size in points (default: 48)
- color: text color
- stroke_width: float, outline thickness
- stroke_color: outline color
- fill_opacity: float, text opacity (0-1)
- slant: str, font style ('NORMAL', 'ITALIC', 'OBLIQUE')
- weight: str, font weight ('NORMAL', 'BOLD')
- t2c: dict, text-to-color mapping for parts of text
- t2f: dict, text-to-font mapping for parts of text
- t2s: dict, text-to-slant mapping for parts of text
- t2w: dict, text-to-weight mapping for parts of text
"""
def get_part_by_text(self, text):
"""
Get submobject containing specific text.
Parameters:
- text: str, text to find
Returns:
VMobject or None
"""
def set_color_by_text(self, text, color):
"""
Set color for specific text substring.
Parameters:
- text: str, text to recolor
- color: new color
Returns:
Text (self)
"""
class MarkupText(VMobject):
def __init__(self, text, **kwargs):
"""
Text with Pango markup support (HTML-like tags).
Parameters:
- text: str, text with markup tags
- color: default text color
- font_size: float, default font size
- line_spacing: float, spacing between lines
- justify: bool, justify text alignment
- indent: float, paragraph indentation
Supported markup:
- <b>bold</b>
- <i>italic</i>
- <u>underline</u>
- <s>strikethrough</s>
- <span color="red">colored text</span>
- <span font_size="24">sized text</span>
"""
class Paragraph(VGroup):
def __init__(self, *text, **kwargs):
"""
Multi-line paragraph with line wrapping.
Parameters:
- text: str or list of str, paragraph content
- line_spacing: float, spacing between lines
- alignment: str, text alignment ('left', 'center', 'right')
"""Comprehensive LaTeX rendering for mathematical notation and equations.
class Tex(VMobject):
def __init__(self, *tex_strings, **kwargs):
"""
Render LaTeX mathematical expressions.
Parameters:
- tex_strings: str arguments, LaTeX code to render
- arg_separator: str, separator between arguments (default: " ")
- substrings_to_isolate: list, LaTeX parts to isolate as submobjects
- font_size: float, text size
- color: default color
- stroke_width: float, outline thickness
- background_stroke_width: float, background outline thickness
- background_stroke_color: background outline color
- tex_environment: str, LaTeX environment ('align*', 'equation*', etc.)
- tex_template: TexTemplate, custom LaTeX template
"""
def get_part_by_tex(self, tex, substring=True):
"""
Get submobject containing specific LaTeX code.
Parameters:
- tex: str, LaTeX code to find
- substring: bool, allow partial matches
Returns:
VMobject or None
"""
def get_parts_by_tex(self, tex, substring=True):
"""
Get all submobjects containing specific LaTeX code.
Parameters:
- tex: str, LaTeX code to find
- substring: bool, allow partial matches
Returns:
VGroup
"""
def set_color_by_tex(self, tex, color, **kwargs):
"""
Set color for specific LaTeX substring.
Parameters:
- tex: str, LaTeX code to recolor
- color: new color
- substring: bool, allow partial matches
Returns:
Tex (self)
"""
def set_color_by_tex_to_color_map(self, tex_to_color_map, **kwargs):
"""
Set colors using tex-to-color mapping.
Parameters:
- tex_to_color_map: dict, mapping from LaTeX to colors
Returns:
Tex (self)
"""
class MathTex(Tex):
def __init__(self, *tex_strings, **kwargs):
"""
LaTeX math mode expressions (automatically wrapped in $...$).
Parameters:
- tex_strings: str arguments, mathematical expressions
"""
class TexText(Tex):
def __init__(self, *tex_strings, **kwargs):
"""
Mixed text and math LaTeX rendering.
Parameters:
- tex_strings: str arguments, text with embedded math ($...$)
- arg_separator: str, separator between arguments
- tex_environment: str, LaTeX environment (default: plain text)
"""
class BulletedList(TexText):
def __init__(self, *items, **kwargs):
"""
Bulleted list with LaTeX rendering.
Parameters:
- items: str arguments, list items
- bullet: str, bullet character (default: "\\cdot")
- buff: float, spacing after bullet
- dot_scale_factor: float, bullet size scaling
"""
class Title(TexText):
def __init__(self, *text_parts, **kwargs):
"""
Title text with larger font and positioning.
Parameters:
- text_parts: str arguments, title content
- scale_factor: float, title scaling (default: 1.5)
- include_underline: bool, add underline
- underline_width: float, underline thickness
"""Syntax-highlighted code display with language support.
class Code(Text):
def __init__(self, code_string, **kwargs):
"""
Syntax-highlighted code display.
Parameters:
- code_string: str, source code to display
- language: str, programming language ('python', 'javascript', 'c++', etc.)
- font: str, monospace font name (default: "Consolas")
- font_size: float, code font size
- line_spacing: float, spacing between code lines
- tab_width: int, spaces per tab character
- background: str, background style ('rectangle', 'window')
- background_stroke_width: float, background border width
- background_stroke_color: background border color
- corner_radius: float, background corner rounding
- style: str, syntax highlighting style ('default', 'monokai', etc.)
- generate_html_string: bool, generate HTML representation
"""
def set_language(self, language):
"""
Change syntax highlighting language.
Parameters:
- language: str, new language name
Returns:
Code (self)
"""Specialized text objects for mathematical and educational content.
class Integer(VMobject):
def __init__(self, number=0, **kwargs):
"""
Integer number display that can be animated.
Parameters:
- number: int, number to display
- number_config: dict, Text configuration for number
- show_ellipsis: bool, show ellipsis for large numbers
- group_with_commas: bool, add comma separators
"""
def set_value(self, number):
"""
Change displayed number.
Parameters:
- number: int, new number to display
Returns:
Integer (self)
"""
def get_value(self):
"""
Get current displayed number.
Returns:
int
"""
def increment_value(self, delta=1):
"""
Increment displayed number.
Parameters:
- delta: int, amount to add
Returns:
Integer (self)
"""
class DecimalNumber(VMobject):
def __init__(self, number=0, **kwargs):
"""
Decimal number display that can be animated.
Parameters:
- number: float, number to display
- num_decimal_places: int, decimal places to show
- include_sign: bool, show + for positive numbers
- group_with_commas: bool, add comma separators
- digit_buff_per_font_unit: float, spacing between digits
- show_ellipsis: bool, show ellipsis for rounding
- unit: str, unit suffix (e.g., "m", "kg")
- include_background_rectangle: bool, add background
- edge_to_fix: np.array, edge to keep fixed during updates
"""
def set_value(self, number):
"""
Change displayed number.
Parameters:
- number: float, new number to display
Returns:
DecimalNumber (self)
"""
def get_value(self):
"""
Get current displayed number.
Returns:
float
"""
def increment_value(self, delta):
"""
Increment displayed number.
Parameters:
- delta: float, amount to add
Returns:
DecimalNumber (self)
"""Utilities for text alignment, layout, and organization.
class VGroup(VMobject):
def arrange(self, direction=RIGHT, **kwargs):
"""
Arrange submobjects in specified direction.
Parameters:
- direction: np.array, arrangement direction
- buff: float, spacing between objects
- center: bool, center the arrangement
- aligned_edge: np.array, edge to align
Returns:
VGroup (self)
"""
def arrange_in_grid(self, rows=None, cols=None, **kwargs):
"""
Arrange submobjects in grid layout.
Parameters:
- rows: int, number of rows
- cols: int, number of columns
- buff: float, spacing between objects
- cell_alignment: np.array, alignment within cells
Returns:
VGroup (self)
"""
def text_alignment_functions():
"""Text alignment utility functions."""
def align_text_left(text_mobject):
"""Align text to left edge."""
def align_text_right(text_mobject):
"""Align text to right edge."""
def align_text_center(text_mobject):
"""Center align text."""
class Underline(Line):
def __init__(self, mobject, **kwargs):
"""
Underline for text objects.
Parameters:
- mobject: Text object to underline
- buff: float, distance below text
"""
class Cross(VGroup):
def __init__(self, mobject, **kwargs):
"""
Cross/strikethrough for text objects.
Parameters:
- mobject: Object to cross out
- stroke_color: Cross line color
- stroke_width: Cross line thickness
"""from manimgl import *
class TextExample(Scene):
def construct(self):
# Create various text objects
plain_text = Text("Hello World", font_size=48)
styled_text = Text(
"Styled Text",
font="Arial",
color=BLUE,
stroke_width=2,
stroke_color=WHITE
)
# Position text
plain_text.shift(UP)
styled_text.shift(DOWN)
# Animate
self.play(Write(plain_text))
self.play(Write(styled_text))
self.wait()class MathExample(Scene):
def construct(self):
# Mathematical expressions
equation = MathTex(
"E", "=", "m", "c^2"
).set_color_by_tex_to_color_map({
"E": YELLOW,
"m": RED,
"c": BLUE
})
# Complex equation
integral = MathTex(
r"\int_0^{\infty} x^2 e^{-x} dx = 2"
)
self.play(Write(equation))
self.wait()
self.play(Transform(equation, integral))
self.wait()class CodeExample(Scene):
def construct(self):
code = Code(
"""
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
""",
language="python",
font_size=36,
background="rectangle",
background_stroke_color=WHITE
)
self.play(ShowCreation(code))
self.wait()class MixedExample(Scene):
def construct(self):
mixed = TexText(
"The quadratic formula is ",
"$x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$",
" for $ax^2 + bx + c = 0$"
)
# Color the math parts
mixed.set_color_by_tex("$", YELLOW)
self.play(Write(mixed))
self.wait()class NumberExample(Scene):
def construct(self):
# Animated decimal
number = DecimalNumber(0, num_decimal_places=2)
number.add_updater(lambda m, dt: m.increment_value(dt))
self.add(number)
self.wait(5) # Number will count up automaticallyInstall with Tessl CLI
npx tessl i tessl/pypi-manimgldocs