manim.mobject.svg.text_mobject

Mobjects used for displaying (non-LaTeX) text.

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

../_images/HelloWorld-1.png
HelloWorld
class HelloWorld(Scene):
    def construct(self):
        text = Text('Hello world').scale(3)
        self.add(text)
../_images/TextAlignment-1.png
TextAlignment
class TextAlignment(Scene):
    def construct(self):
        title = Text("K-means clustering and Logistic Regression", color=WHITE)
        title.scale_in_place(0.75)
        self.add(title.to_edge(UP))

        t1 = Text("1. Measuring").set_color(WHITE)
        t1.next_to(ORIGIN, direction=RIGHT, aligned_edge=UP)

        t2 = Text("2. Clustering").set_color(WHITE)
        t2.next_to(t1, direction=DOWN, aligned_edge=LEFT)

        t3 = Text("3. Regression").set_color(WHITE)
        t3.next_to(t2, direction=DOWN, aligned_edge=LEFT)

        t4 = Text("4. Prediction").set_color(WHITE)
        t4.next_to(t3, direction=DOWN, aligned_edge=LEFT)

        x = VGroup(t1, t2, t3, t4).scale_in_place(0.7)
        x.set_opacity(0.5)
        x.submobjects[1].set_opacity(1)
        self.add(x)

Classes

CairoText

Display (non-LaTeX) text.

MarkupText

Display (non-LaTeX) text rendered using Pango.

Paragraph

Display a paragraph of text.

Text

Display (non-LaTeX) text rendered using Pango.

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.

  1. Absolute path.

  2. In assets/fonts folder.

  3. In font/ folder.

  4. In the same directory.

Parameters

font_file (Union[str, pathlib.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.

Parameters

font_file (Union[str, pathlib.Path]) –

Notes

This method of adding font files also works with CairoText.

Important

This method is available for macOS for ManimPango>=v0.2.3. Using this method with previous releases will raise an AttributeError on macOS.

remove_invisible_chars(mobject)[source]

Function to remove unwanted invisible characters from some mobject

Parameters

mobject (SVGMobject) – Any SVGMobject from which we want to remove unwanted invisible characters.

Returns

The SVGMobject without unwanted invisible characters.

Return type

SVGMobject