manim.mobject.svg.text_mobject.Text

class Text(text, fill_opacity=1.0, stroke_width=0, color='#FFFFFF', size=1, line_spacing=- 1, font='', slant='NORMAL', weight='NORMAL', t2c=None, t2f=None, t2g=None, t2s=None, t2w=None, gradient=None, tab_width=4, height=None, width=None, should_center=True, unpack_groups=True, disable_ligatures=False, **kwargs)[source]

Bases: manim.mobject.svg.svg_mobject.SVGMobject

Display (non-LaTeX) text rendered using Pango.

Text objects behave like a VGroup-like iterable of all characters in the given text. In particular, slicing is possible.

Parameters
  • text (str) – The text that need to created as mobject.

  • fill_opacity (float) –

  • stroke_width (int) –

  • color (str) –

  • size (int) –

  • line_spacing (int) –

  • font (str) –

  • slant (str) –

  • weight (str) –

  • t2c (Dict[str, str]) –

  • t2f (Dict[str, str]) –

  • t2g (Dict[str, tuple]) –

  • t2s (Dict[str, str]) –

  • t2w (Dict[str, str]) –

  • gradient (tuple) –

  • tab_width (int) –

  • height (int) –

  • width (int) –

  • should_center (bool) –

  • unpack_groups (bool) –

  • disable_ligatures (bool) –

Returns

The mobject like VGroup.

Return type

Text

Examples

Example: Example1Text

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

class Example1Text(Scene):
    def construct(self):
        text = Text('Hello world').scale(3)
        self.add(text)

Example: TextColorExample

../_images/TextColorExample-1.png
from manim import *

class TextColorExample(Scene):
    def construct(self):
        text1 = Text('Hello world', color=BLUE).scale(3)
        text2 = Text('Hello world', gradient=(BLUE, GREEN)).scale(3).next_to(text1, DOWN)
        self.add(text1, text2)

Example: TextItalicAndBoldExample

../_images/TextItalicAndBoldExample-1.png
from manim import *

class TextItalicAndBoldExample(Scene):
    def construct(self):
        text1 = Text("Hello world", slant=ITALIC)
        text2 = Text("Hello world", t2s={'world':ITALIC})
        text3 = Text("Hello world", weight=BOLD)
        text4 = Text("Hello world", t2w={'world':BOLD})
        text5 = Text("Hello world", t2c={'o':YELLOW}, disable_ligatures=True)
        text6 = Text(
            "Visit us at docs.manim.community",
            t2c={"docs.manim.community": YELLOW},
            disable_ligatures=True,
       )
        text6.scale(1.3).shift(DOWN)
        self.add(text1, text2, text3, text4, text5 , text6)
        Group(*self.mobjects).arrange(DOWN, buff=.8).set_height(config.frame_height-LARGE_BUFF)

Example: TextMoreCustomization

../_images/TextMoreCustomization-1.png
from manim import *

class TextMoreCustomization(Scene):
    def construct(self):
        text1 = Text(
            'Google',
            t2c={'[:1]': '#3174f0', '[1:2]': '#e53125',
                 '[2:3]': '#fbb003', '[3:4]': '#3174f0',
                 '[4:5]': '#269a43', '[5:]': '#e53125'}, size=1.2).scale(3)
        self.add(text1)

As Text uses Pango to render text, rendering non-English characters is easily possible:

Example: MultipleFonts

../_images/MultipleFonts-1.png
from manim import *

class MultipleFonts(Scene):
    def construct(self):
        morning = Text("வணக்கம்", font="sans-serif")
        chin = Text(
            "見 角 言 谷  辛 辰 辵 邑 酉 釆 里!", t2c={"見 角 言": BLUE}
        )  # works same as ``Text``.
        mess = Text("Multi-Language", weight=BOLD)
        russ = Text("Здравствуйте मस नम म ", font="sans-serif")
        hin = Text("नमस्ते", font="sans-serif")
        arb = Text(
            "صباح الخير \n تشرفت بمقابلتك", font="sans-serif"
        )  # don't mix RTL and LTR languages nothing shows up then ;-)
        japanese = Text("臂猿「黛比」帶著孩子", font="sans-serif")
        self.add(morning,chin,mess,russ,hin,arb,japanese)
        for i,mobj in enumerate(self.mobjects):
            mobj.shift(DOWN*(i-3))

Example: PangoRender

from manim import *

class PangoRender(Scene):
    def construct(self):
        morning = Text("வணக்கம்", font="sans-serif")
        self.play(Write(morning))
        self.wait(2)

Tests

Check that the creation of Text works:

>>> Text('The horse does not eat cucumber salad.')
Text('The horse does not eat cucumber salad.')

Methods

find_indexes

Internally used function.

gen_chars

init_colors

Initializes the colors.

set_color_by_t2c

Internally used function.

set_color_by_t2g

Internally used.

text2hash

Internally used function.

text2settings

Internally used function.

text2svg

Internally used function.

Attributes

animate

Used to animate the application of a method.

animation_overrides

depth

The depth of the mobject.

height

The height of the mobject.

width

The width of the mobject.

find_indexes(word, text)[source]

Internally used function. Finds the indexes of text in word.

Parameters
  • word (str) –

  • text (str) –

init_colors(propagate_colors=True)[source]

Initializes the colors.

Gets called upon creation. This is an empty method that can be implemented by subclasses.

set_color_by_t2c(t2c=None)[source]

Internally used function. Sets color for specified strings.

set_color_by_t2g(t2g=None)[source]

Internally used. Sets gradient colors for specified strings. Behaves similarly to set_color_by_t2c.

text2hash()[source]

Internally used function. Generates sha256 hash for file name.

text2settings()[source]

Internally used function. Converts the texts and styles to a setting for parsing.

text2svg()[source]

Internally used function. Convert the text to SVG using Pango