manim.mobject.svg.text_mobject.Text

class Text(text, fill_opacity=1, 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 (int) –

  • 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

../_images/Example1Text-1.png
Example1Text
class Example1Text(Scene):
    def construct(self):
        text = Text('Hello world').scale(3)
        self.add(text)
../_images/TextColorExample-1.png
TextColorExample
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)
../_images/TextItalicAndBoldExample-1.png
TextItalicAndBoldExample
class TextItalicAndBoldExample(Scene):
    def construct(self):
        text0 = Text('Hello world', slant=ITALIC)
        text1 = Text('Hello world', t2s={'world':ITALIC})
        text2 = Text('Hello world', weight=BOLD)
        text3 = Text('Hello world', t2w={'world':BOLD})
        self.add(text0,text1, text2,text3)
        for i,mobj in enumerate(self.mobjects):
            mobj.shift(DOWN*(i-1))
../_images/TextMoreCustomization-1.png
TextMoreCustomization
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:

../_images/MultipleFonts-1.png
MultipleFonts
class MultipleFonts(Scene):
    def construct(self):
        morning = Text("வணக்கம்", font="sans-serif")
        chin = Text(
            "見 角 言 谷  辛 辰 辵 邑 酉 釆 里!", t2c={"見 角 言": BLUE}
        )  # works same as ``Text``.
        mess = Text("Multi-Language", style=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))
PangoRender
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

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.

find_indexes(word, text)[source]

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

Parameters
  • word (str) –

  • text (str) –

set_color_by_t2c(t2c=None)[source]

Internally used function. Sets colour 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