Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/examples/advanced_projects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Advanced Projects

def add_x_labels(self):
x_labels = [
TexMobject("\pi"), TexMobject("2 \pi"),
TexMobject("3 \pi"), TexMobject("4 \pi"),
MathTex("\pi"), MathTex("2 \pi"),
MathTex("3 \pi"), MathTex("4 \pi"),
]

for i in range(len(x_labels)):
Expand Down
32 changes: 32 additions & 0 deletions docs/source/examples/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,35 @@ Annotations
b2text = b2.get_tex("x-x_1")
self.add(dot, dot2, line, b1, b2, b1text, b2text)

.. manim:: ExampleArrow
:quality: medium
:save_last_frame:

class ExampleArrow(Scene):
def construct(self):
dot = Dot(ORIGIN)
arrow = Arrow(ORIGIN, [2, 2, 0], buff=0)
numberplane = NumberPlane()
origin_text = TextMobject('(0, 0)').next_to(dot, DOWN)
tip_text = TextMobject('(2, 2)').next_to(arrow.get_end(), RIGHT)
self.add(numberplane, dot, arrow, origin_text, tip_text)

.. manim:: ExampleArrowTips
:quality: medium
:save_last_frame:

from manim.mobject.geometry import ArrowTriangleTip, ArrowSquareTip, ArrowSquareFilledTip,\
ArrowCircleTip, ArrowCircleFilledTip
class ExampleArrowTips(Scene):
def construct(self):
a00 = Arrow(start=[-2, 3, 0], end=[2, 3, 0], color=YELLOW)
a11 = Arrow(start=[-2, 2, 0], end=[2, 2, 0], tip_shape=ArrowTriangleTip)
a12 = Arrow(start=[-2, 1, 0], end=[2, 1, 0])
a21 = Arrow(start=[-2, 0, 0], end=[2, 0, 0], tip_shape=ArrowSquareTip)
a22 = Arrow([-2, -1, 0], [2, -1, 0], tip_shape=ArrowSquareFilledTip)
a31 = Arrow([-2, -2, 0], [2, -2, 0], tip_shape=ArrowCircleTip)
a32 = Arrow([-2, -3, 0], [2, -3, 0], tip_shape=ArrowCircleFilledTip)
b11 = a11.copy().scale(0.5, scale_tips=True).next_to(a11, RIGHT)
b12 = a12.copy().scale(0.5, scale_tips=True).next_to(a12, RIGHT)
b21 = a21.copy().scale(0.5, scale_tips=True).next_to(a21, RIGHT)
self.add(a00, a11, a12, a21, a22, a31, a32, b11, b12, b21)
11 changes: 2 additions & 9 deletions docs/source/examples/formulas.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
Formulas
=================================

.. manim:: Formula1
:save_last_frame:

class Formula1(Scene):
def construct(self):
t = MathTex(r"\int_a^b f'(x) dx = f(b)- f(a)")
self.add(t)
self.wait(1)


.. manim:: MoveFrameBox

class MoveFrameBox(Scene):
def construct(self):
text=TexMobject(
text=MathTex(
"\\frac{d}{dx}f(x)g(x)=","f(x)\\frac{d}{dx}g(x)","+",
"g(x)\\frac{d}{dx}f(x)"
)
Expand All @@ -35,7 +28,7 @@ Formulas

class MoveBraces(Scene):
def construct(self):
text=TexMobject(
text=MathTex(
"\\frac{d}{dx}f(x)g(x)=", #0
"f(x)\\frac{d}{dx}g(x)", #1
"+", #2
Expand Down
106 changes: 2 additions & 104 deletions docs/source/examples/text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,108 +9,6 @@ Text
text = Text('Hello world').scale(3)
self.add(text)

.. manim:: Example2Text
:save_last_frame:

class Example2Text(Scene):
def construct(self):
text = Text('Hello world', color=BLUE).scale(3)
self.add(text)


.. manim:: Example3Text
:save_last_frame:

class Example3Text(Scene):
def construct(self):
text = Text('Hello world', gradient=(BLUE, GREEN)).scale(3)
self.add(text)


.. manim:: Example4Text
:save_last_frame:

class Example4Text(Scene):
def construct(self):
text = Text('Hello world', t2g={'world':(BLUE, GREEN)}).scale(3)
self.add(text)

.. manim:: Example5Text
:save_last_frame:

class Example5Text(Scene):
def construct(self):
text = Text('Hello world', font='Source Han Sans').scale(3)
self.add(text)

.. manim:: Example5bText
:save_last_frame:

class Example5bText(Scene):
def construct(self):
text = Text('Hello world', t2f={'world':'Forte'}).scale(3)
self.add(text)

.. manim:: Example6Text
:save_last_frame:

class Example6Text(Scene):
def construct(self):
text = Text('Hello world', slant=ITALIC).scale(3)
self.add(text)

.. manim:: Example7Text
:save_last_frame:

class Example7Text(Scene):
def construct(self):
text = Text('Hello world!', t2s={'world':ITALIC}).scale(3)
self.add(text)

.. manim:: Example8Text
:save_last_frame:

class Example8Text(Scene):
def construct(self):
text = Text('Hello world', weight=BOLD).scale(3)
self.add(text)

.. manim:: Example9Text
:save_last_frame:

class Example9Text(Scene):
def construct(self):
text = Text('Hello world', t2w={'world':BOLD}).scale(3)
self.add(text)

.. manim:: Example10Text
:save_last_frame:

class Example10Text(Scene):
def construct(self):
text = Text('Hello', size=0.3).scale(3)
self.add(text)

.. manim:: Example11Text
:save_last_frame:

class Example11Text(Scene):
def construct(self):
text = Text('Hello\nWorld', lsh=1.5).scale(3)
self.add(text)

.. manim:: Example12Text
:save_last_frame:

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

`Text` works also with other languages like `你好` or `こんにちは` or `안녕하세요` or `مرحبا بالعالم`.
Be sure you have the font that supports those languages!
This is an example that illustrates how to use the :class:`~.Text` class.

In case you want to use other alphabets like `你好` or `こんにちは` or `안녕하세요` or `مرحبا بالعالم`, you can have a look at :class:`~.PangoText`
15 changes: 15 additions & 0 deletions manim/mobject/svg/tex_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ def organize_submobjects_left_to_right(self):


class MathTex(SingleStringMathTex):
"""
A class for displaying mathematical formulas with Latex syntax.
Examples
--------
.. manim:: Formula1
:save_last_frame:
class Formula1(Scene):
def construct(self):
t = MathTex(r"\int_a^b f'(x) dx = f(b)- f(a)")
self.add(t)
"""

CONFIG = {
"arg_separator": " ",
"substrings_to_isolate": [],
Expand Down
50 changes: 50 additions & 0 deletions manim/mobject/svg/text_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ class CairoText(SVGMobject):
Text objects behave like a :class:`.VGroup`-like iterable of all characters
in the given text. In particular, slicing is possible.



.. WARNING::

Using a :class:`.Transform` on text with leading whitespace can look
`weird <https://github.com/3b1b/manim/issues/1067>`_. Consider using
:meth:`remove_invisible_chars` to resolve this issue.




"""

CONFIG = {
Expand Down Expand Up @@ -896,6 +901,51 @@ class Text(CairoText):
Text objects behave like a :class:`.VGroup`-like iterable of all characters
in the given text. In particular, slicing is possible.

Examples
--------
.. manim:: Example1Text
:save_last_frame:

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

.. manim:: TextColorExample
:save_last_frame:

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)

.. manim:: TextItalicAndBoldExample
:save_last_frame:

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))


.. manim:: TextMoreCustomization
:save_last_frame:

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)

.. WARNING::

Using a :class:`.Transform` on text with leading whitespace can look
Expand Down