text_mobject¶
Mobjects used for displaying (non-LaTeX) text.
Note
Just as you can use Tex
and MathTex
(from the module tex_mobject
)
to insert LaTeX to your videos, you can use Text
to to add normal text.
Important
See the corresponding tutorial Text Without LaTeX, especially for information about fonts.
The simplest way to add text to your animations is to use the Text
class. It uses the Pango library to render text.
With Pango, you are also able to render non-English alphabets like 你好 or こんにちは or 안녕하세요 or مرحبا بالعالم.
Examples
Example: HelloWorld ¶

from manim import *
class HelloWorld(Scene):
def construct(self):
text = Text('Hello world').scale(3)
self.add(text)
class HelloWorld(Scene): def construct(self): text = Text('Hello world').scale(3) self.add(text)
Example: TextAlignment ¶

from manim import *
class TextAlignment(Scene):
def construct(self):
title = Text("K-means clustering and Logistic Regression", color=WHITE)
title.scale(0.75)
self.add(title.to_edge(UP))
t1 = Text("1. Measuring").set_color(WHITE)
t2 = Text("2. Clustering").set_color(WHITE)
t3 = Text("3. Regression").set_color(WHITE)
t4 = Text("4. Prediction").set_color(WHITE)
x = VGroup(t1, t2, t3, t4).arrange(direction=DOWN, aligned_edge=LEFT).scale(0.7).next_to(ORIGIN,DR)
x.set_opacity(0.5)
x.submobjects[1].set_opacity(1)
self.add(x)
class TextAlignment(Scene): def construct(self): title = Text("K-means clustering and Logistic Regression", color=WHITE) title.scale(0.75) self.add(title.to_edge(UP)) t1 = Text("1. Measuring").set_color(WHITE) t2 = Text("2. Clustering").set_color(WHITE) t3 = Text("3. Regression").set_color(WHITE) t4 = Text("4. Prediction").set_color(WHITE) x = VGroup(t1, t2, t3, t4).arrange(direction=DOWN, aligned_edge=LEFT).scale(0.7).next_to(ORIGIN,DR) x.set_opacity(0.5) x.submobjects[1].set_opacity(1) self.add(x)
Classes
Display (non-LaTeX) text rendered using Pango. |
|
Display a paragraph of text. |
|
Functions
- register_font(font_file)[source]¶
Temporarily add a font file to Pango’s search path.
This searches for the font_file at various places. The order it searches it described below.
Absolute path.
In
assets/fonts
folder.In
font/
folder.In the same directory.
- Parameters:
font_file (str | Path) – The font file to add.
Examples
Use
with register_font(...)
to add a font file to search path.with register_font("path/to/font_file.ttf"): a = Text("Hello", font="Custom Font Name")
- Raises:
FileNotFoundError: – If the font doesn’t exists.
AttributeError: – If this method is used on macOS.
.. important :: – This method is available for macOS for
ManimPango>=v0.2.3
. Using this method with previous releases will raise anAttributeError
on macOS.
- Parameters:
font_file (str | Path)
- remove_invisible_chars(mobject)[source]¶
Function to remove unwanted invisible characters from some mobjects.
- Parameters:
mobject (SVGMobject) – Any SVGMobject from which we want to remove unwanted invisible characters.
- Returns:
The SVGMobject without unwanted invisible characters.
- Return type: