Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Deprecate `TexMobject` and `TextMobject` in favour of `MathTex` and `Tex` (#391)

Aathish Sivasubrahmanian6df53cc9f7b7
diff --git a/docs/source/installation/linux.rst b/docs/source/installation/linux.rst
index c3d9253e9..c2299e739 100644
--- a/docs/source/installation/linux.rst
+++ b/docs/source/installation/linux.rst
@@ -8,7 +8,7 @@ dependencies are installed correctly. All distributions will follow the same
instructions in `Certifying a clean install`_.
The two necessary dependencies are cairo and ffmpeg. LaTeX is strongly
-recommended, as it is necessary to have access to the ``TexMobject`` class.
+recommended, as it is necessary to have access to the ``Tex`` and ``MathTex`` classes.
Sox is only required if you want manim to play sounds when rendering scenes.
Ubuntu/Debian
diff --git a/example_scenes/basic.py b/example_scenes/basic.py
index 79238f309..ea890febe 100644
--- a/example_scenes/basic.py
+++ b/example_scenes/basic.py
@@ -17,15 +17,15 @@ from manim import *
class OpeningManimExample(Scene):
def construct(self):
- title = TextMobject("This is some \\LaTeX")
- basel = TexMobject("\\sum_{n=1}^\\infty " "\\frac{1}{n^2} = \\frac{\\pi^2}{6}")
+ title = Tex("This is some \\LaTeX")
+ basel = MathTex("\\sum_{n=1}^\\infty " "\\frac{1}{n^2} = \\frac{\\pi^2}{6}")
VGroup(title, basel).arrange(DOWN)
self.play(
Write(title), FadeInFrom(basel, UP),
)
self.wait()
- transform_title = TextMobject("That was a transform")
+ transform_title = Tex("That was a transform")
transform_title.to_corner(UP + LEFT)
self.play(
Transform(title, transform_title),
@@ -34,7 +34,7 @@ class OpeningManimExample(Scene):
self.wait()
grid = NumberPlane()
- grid_title = TextMobject("This is a grid")
+ grid_title = Tex("This is a grid")
grid_title.scale(1.5)
grid_title.move_to(transform_title)
@@ -46,7 +46,7 @@ class OpeningManimExample(Scene):
)
self.wait()
- grid_transform_title = TextMobject(
+ grid_transform_title = Tex(
"That was a non-linear function \\\\" "applied to the grid"
)
grid_transform_title.move_to(grid_title, UL)
@@ -87,12 +87,8 @@ class WarpSquare(Scene):
class WriteStuff(Scene):
def construct(self):
- example_text = TextMobject(
- "This is a some text", tex_to_color_map={"text": YELLOW}
- )
- example_tex = TexMobject(
- "\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",
- )
+ example_text = Tex("This is a some text", tex_to_color_map={"text": YELLOW})
+ example_tex = MathTex("\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",)
group = VGroup(example_text, example_tex)
group.arrange(DOWN)
group.set_width(config["frame_width"] - 2 * LARGE_BUFF)
@@ -131,7 +127,7 @@ class VDictExample(Scene):
self.play(ShowCreation(my_dict))
self.wait()
- text = TextMobject("Some text").set_color(GREEN).next_to(square, DOWN)
+ text = Tex("Some text").set_color(GREEN).next_to(square, DOWN)
# add a key-value pair by wrapping it in a single-element list of tuple
# after attrs branch is merged, it will be easier like `.add(t=text)`
@@ -148,7 +144,7 @@ class VDictExample(Scene):
self.wait()
# also supports python dict styled reassignment
- my_dict["t"] = TextMobject("Some other text").set_color(BLUE)
+ my_dict["t"] = Tex("Some other text").set_color(BLUE)
self.wait()
# remove submoject by key
diff --git a/example_scenes/customtex.py b/example_scenes/customtex.py
index 64a9ab59d..bb50bb455 100644
--- a/example_scenes/customtex.py
+++ b/example_scenes/customtex.py
@@ -11,8 +11,8 @@ class TexTemplateFromCLI(Scene):
"""
def construct(self):
- text = TexMobject(r"\vv{vb}")
- # text=TextMobject(r"$\vv{vb}$")
+ text = MathTex(r"\vv{vb}")
+ # text=Tex(r"$\vv{vb}$")
self.play(Write(text))
@@ -26,6 +26,6 @@ class InCodeTexTemplate(Scene):
tpl.append_package(["esvect", ["f"]])
config["tex_template"] = tpl
- # text=TextMobject(r"$\vv{vb}$")
- text = TexMobject(r"\vv{vb}")
+ # text=Tex(r"$\vv{vb}$")
+ text = MathTex(r"\vv{vb}")
self.play(Write(text))
diff --git a/logo/logo.py b/logo/logo.py
index 4ff3e8c68..235b6c608 100644
--- a/logo/logo.py
+++ b/logo/logo.py
@@ -74,10 +74,10 @@ class Thumbnail(GraphScene):
triangle.scale(0.1)
#
- x_label_p1 = TexMobject("a")
- output_label_p1 = TexMobject("f(a)")
- x_label_p2 = TexMobject("b")
- output_label_p2 = TexMobject("f(b)")
+ x_label_p1 = MathTex("a")
+ output_label_p1 = MathTex("f(a)")
+ x_label_p2 = MathTex("b")
+ output_label_p2 = MathTex("f(b)")
v_line_p1 = get_v_line(input_tracker_p1)
v_line_p2 = get_v_line(input_tracker_p2)
h_line_p1 = get_h_line(input_tracker_p1)
@@ -181,10 +181,5 @@ class Thumbnail(GraphScene):
# adding manim
picture = Group(*self.mobjects)
picture.scale(0.6).to_edge(LEFT, buff=SMALL_BUFF)
- manim = (
- TextMobject("Manim")
- .set_height(1.5)
- .next_to(picture, RIGHT)
- .shift(DOWN * 0.7)
- )
+ manim = Tex("Manim").set_height(1.5).next_to(picture, RIGHT).shift(DOWN * 0.7)
self.add(manim)
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py
index 0bed1d4c2..d5b60cf30 100644
--- a/manim/mobject/coordinate_systems.py
+++ b/manim/mobject/coordinate_systems.py
@@ -10,7 +10,7 @@ from ..mobject.functions import ParametricFunction
from ..mobject.geometry import Arrow
from ..mobject.geometry import Line
from ..mobject.number_line import NumberLine
-from ..mobject.svg.tex_mobject import TexMobject
+from ..mobject.svg.tex_mobject import MathTex
from ..mobject.types.vectorized_mobject import VGroup
from ..utils.config_ops import digest_config
from ..utils.config_ops import merge_dicts_recursively
@@ -73,7 +73,7 @@ class CoordinateSystem:
)
def get_axis_label(self, label_tex, axis, edge, direction, buff=MED_SMALL_BUFF):
- label = TexMobject(label_tex)
+ label = MathTex(label_tex)
label.next_to(axis.get_edge_center(edge), direction, buff=buff)
label.shift_onto_screen(buff=MED_SMALL_BUFF)
return label
diff --git a/manim/mobject/matrix.py b/manim/mobject/matrix.py
index 30e7db90e..80f258cde 100644
--- a/manim/mobject/matrix.py
+++ b/manim/mobject/matrix.py
@@ -16,8 +16,8 @@ from ..constants import *
from ..mobject.numbers import DecimalNumber
from ..mobject.numbers import Integer
from ..mobject.shape_matchers import BackgroundRectangle
-from ..mobject.svg.tex_mobject import TexMobject
-from ..mobject.svg.tex_mobject import TextMobject
+from ..mobject.svg.tex_mobject import MathTex
+from ..mobject.svg.tex_mobject import Tex
from ..mobject.types.vectorized_mobject import VGroup
from ..mobject.types.vectorized_mobject import VMobject
@@ -36,7 +36,7 @@ def matrix_to_tex_string(matrix):
def matrix_to_mobject(matrix):
- return TexMobject(matrix_to_tex_string(matrix))
+ return MathTex(matrix_to_tex_string(matrix))
def vector_coordinate_label(vector_mob, integer_labels=True, n_dim=2, color=WHITE):
@@ -68,7 +68,7 @@ class Matrix(VMobject):
"bracket_v_buff": MED_SMALL_BUFF,
"add_background_rectangles_to_entries": False,
"include_background_rectangle": False,
- "element_to_mobject": TexMobject,
+ "element_to_mobject": MathTex,
"element_to_mobject_config": {},
"element_alignment_corner": DR,
"left_bracket": "\\big[",
@@ -111,7 +111,7 @@ class Matrix(VMobject):
return self
def add_brackets(self, left="\\big[", right="\\big]"):
- bracket_pair = TexMobject(left, right)
+ bracket_pair = MathTex(left, right)
bracket_pair.scale(2)
bracket_pair.stretch_to_fit_height(self.get_height() + 2 * self.bracket_v_buff)
l_bracket, r_bracket = bracket_pair.split()
@@ -199,22 +199,22 @@ class MobjectMatrix(Matrix):
def get_det_text(
matrix, determinant=None, background_rect=False, initial_scale_factor=2
):
- parens = TexMobject("(", ")")
+ parens = MathTex("(", ")")
parens.scale(initial_scale_factor)
parens.stretch_to_fit_height(matrix.get_height())
l_paren, r_paren = parens.split()
l_paren.next_to(matrix, LEFT, buff=0.1)
r_paren.next_to(matrix, RIGHT, buff=0.1)
- det = TextMobject("det")
+ det = Tex("det")
det.scale(initial_scale_factor)
det.next_to(l_paren, LEFT, buff=0.1)
if background_rect:
det.add_background_rectangle()
det_text = VGroup(det, l_paren, r_paren)
if determinant is not None:
- eq = TexMobject("=")
+ eq = MathTex("=")
eq.next_to(r_paren, RIGHT, buff=0.1)
- result = TexMobject(str(determinant))
+ result = MathTex(str(determinant))
result.next_to(eq, RIGHT, buff=0.2)
det_text.add(eq, result)
return det_text
diff --git a/manim/mobject/numbers.py b/manim/mobject/numbers.py
index 79335c4f7..fbbadca50 100644
--- a/manim/mobject/numbers.py
+++ b/manim/mobject/numbers.py
@@ -2,7 +2,7 @@ __all__ = ["DecimalNumber", "Integer"]
from ..constants import *
-from ..mobject.svg.tex_mobject import SingleStringTexMobject
+from ..mobject.svg.tex_mobject import SingleStringMathTex
from ..mobject.types.vectorized_mobject import VMobject
@@ -36,18 +36,18 @@ class DecimalNumber(VMobject):
else:
num_string = num_string[1:]
- self.add(*[SingleStringTexMobject(char, **kwargs) for char in num_string])
+ self.add(*[SingleStringMathTex(char, **kwargs) for char in num_string])
# Add non-numerical bits
if self.show_ellipsis:
- self.add(SingleStringTexMobject("\\dots"))
+ self.add(SingleStringMathTex("\\dots"))
if num_string.startswith("-"):
minus = self.submobjects[0]
minus.next_to(self.submobjects[1], LEFT, buff=self.digit_to_digit_buff)
if self.unit is not None:
- self.unit_sign = SingleStringTexMobject(self.unit, color=self.color)
+ self.unit_sign = SingleStringMathTex(self.unit, color=self.color)
self.add(self.unit_sign)
self.arrange(buff=self.digit_to_digit_buff, aligned_edge=DOWN)
@@ -79,7 +79,11 @@ class DecimalNumber(VMobject):
config = dict(
[
(attr, getattr(self, attr))
- for attr in ["include_sign", "group_with_commas", "num_decimal_places",]
+ for attr in [
+ "include_sign",
+ "group_with_commas",
+ "num_decimal_places",
+ ]
]
)
config.update(kwargs)
diff --git a/manim/mobject/probability.py b/manim/mobject/probability.py
index 2a7ce7597..670d38112 100644
--- a/manim/mobject/probability.py
+++ b/manim/mobject/probability.py
@@ -6,8 +6,8 @@ from ..mobject.geometry import Line
from ..mobject.geometry import Rectangle
from ..mobject.mobject import Mobject
from ..mobject.svg.brace import Brace
-from ..mobject.svg.tex_mobject import TexMobject
-from ..mobject.svg.tex_mobject import TextMobject
+from ..mobject.svg.tex_mobject import MathTex
+from ..mobject.svg.tex_mobject import Tex
from ..mobject.types.vectorized_mobject import VGroup
from ..utils.color import color_gradient
from ..utils.iterables import tuplify
@@ -29,7 +29,7 @@ class SampleSpace(Rectangle):
def add_title(self, title="Sample space", buff=MED_SMALL_BUFF):
# TODO, should this really exist in SampleSpaceScene
- title_mob = TextMobject(title)
+ title_mob = Tex(title)
if title_mob.get_width() > self.get_width():
title_mob.set_width(self.get_width())
title_mob.next_to(self, UP, buff=buff)
@@ -86,7 +86,7 @@ class SampleSpace(Rectangle):
if isinstance(label, Mobject):
label_mob = label
else:
- label_mob = TexMobject(label)
+ label_mob = MathTex(label)
label_mob.scale(self.default_label_scale_val)
label_mob.next_to(brace, direction, buff)
@@ -179,7 +179,7 @@ class BarChart(VGroup):
if self.label_y_axis:
labels = VGroup()
for tick, value in zip(ticks, values):
- label = TexMobject(str(np.round(value, 2)))
+ label = MathTex(str(np.round(value, 2)))
label.set_height(self.y_axis_label_height)
label.next_to(tick, LEFT, SMALL_BUFF)
labels.add(label)
@@ -202,7 +202,7 @@ class BarChart(VGroup):
bar_labels = VGroup()
for bar, name in zip(bars, self.bar_names):
- label = TexMobject(str(name))
+ label = MathTex(str(name))
label.scale(self.bar_label_scale_val)
label.next_to(bar, DOWN, SMALL_BUFF)
bar_labels.add(label)
diff --git a/manim/mobject/svg/brace.py b/manim/mobject/svg/brace.py
index 47c742293..27c2a1427 100644
--- a/manim/mobject/svg/brace.py
+++ b/manim/mobject/svg/brace.py
@@ -7,14 +7,14 @@ from ...animation.composition import AnimationGroup
from ...constants import *
from ...animation.fading import FadeIn
from ...animation.growing import GrowFromCenter
-from ...mobject.svg.tex_mobject import TexMobject
-from ...mobject.svg.tex_mobject import TextMobject
+from ...mobject.svg.tex_mobject import MathTex
+from ...mobject.svg.tex_mobject import Tex
from ...mobject.types.vectorized_mobject import VMobject
from ...utils.config_ops import digest_config
from ...utils.space_ops import get_norm
-class Brace(TexMobject):
+class Brace(MathTex):
CONFIG = {
"buff": 0.2,
"width_multiplier": 2,
@@ -38,7 +38,7 @@ class Brace(TexMobject):
self.max_num_quads,
)
tex_string = "\\underbrace{%s}" % (num_quads * "\\qquad")
- TexMobject.__init__(self, tex_string, **kwargs)
+ MathTex.__init__(self, tex_string, **kwargs)
self.tip_point_index = np.argmin(self.get_all_points()[:, 1])
self.stretch_to_fit_width(target_width)
self.shift(left - self.get_corner(UP + LEFT) + self.buff * DOWN)
@@ -56,12 +56,12 @@ class Brace(TexMobject):
return self
def get_text(self, *text, **kwargs):
- text_mob = TextMobject(*text)
+ text_mob = Tex(*text)
self.put_at_tip(text_mob, **kwargs)
return text_mob
def get_tex(self, *tex, **kwargs):
- tex_mob = TexMobject(*tex)
+ tex_mob = MathTex(*tex)
self.put_at_tip(tex_mob, **kwargs)
return tex_mob
@@ -78,7 +78,7 @@ class Brace(TexMobject):
class BraceLabel(VMobject):
CONFIG = {
- "label_constructor": TexMobject,
+ "label_constructor": MathTex,
"label_scale": 1,
}
@@ -126,4 +126,4 @@ class BraceLabel(VMobject):
class BraceText(BraceLabel):
- CONFIG = {"label_constructor": TextMobject}
+ CONFIG = {"label_constructor": Tex}
diff --git a/manim/mobject/svg/drawings.py b/manim/mobject/svg/drawings.py
index 2bc9d870c..869ead443 100644
--- a/manim/mobject/svg/drawings.py
+++ b/manim/mobject/svg/drawings.py
@@ -41,8 +41,8 @@ from ...mobject.geometry import Rectangle
from ...mobject.geometry import Square
from ...mobject.mobject import Mobject
from ...mobject.svg.svg_mobject import SVGMobject
-from ...mobject.svg.tex_mobject import TexMobject
-from ...mobject.svg.tex_mobject import TextMobject
+from ...mobject.svg.tex_mobject import MathTex
+from ...mobject.svg.tex_mobject import Tex
from ...mobject.three_dimensions import Cube
from ...mobject.types.vectorized_mobject import VGroup
from ...mobject.types.vectorized_mobject import VMobject
@@ -111,7 +111,7 @@ class Speedometer(VMobject):
for index, angle in enumerate(tick_angle_range):
vect = rotate_vector(RIGHT, angle)
tick = Line((1 - self.tick_length) * vect, vect)
- label = TexMobject(str(10 * index))
+ label = MathTex(str(10 * index))
label.set_height(self.tick_length)
label.shift((1 + self.tick_length) * vect)
self.add(tick, label)
@@ -255,7 +255,11 @@ class Laptop(VGroup):
body.add(keyboard)
screen_plate.stretch(self.screen_thickness / self.body_dimensions[2], dim=2)
- screen = Rectangle(stroke_width=0, fill_color=BLACK, fill_opacity=1,)
+ screen = Rectangle(
+ stroke_width=0,
+ fill_color=BLACK,
+ fill_opacity=1,
+ )
screen.replace(screen_plate, stretch=True)
screen.scale_in_place(self.screen_width_to_screen_plate_width)
screen.next_to(screen_plate, OUT, buff=0.1 * SMALL_BUFF)
@@ -466,7 +470,7 @@ class Bubble(SVGMobject):
return self.content
def write(self, *text):
- self.add_content(TextMobject(*text))
+ self.add_content(Tex(*text))
return self
def resize_to_content(self):
@@ -593,7 +597,10 @@ class VectorizedEarth(SVGMobject):
def __init__(self, **kwargs):
SVGMobject.__init__(self, **kwargs)
circle = Circle(
- stroke_width=3, stroke_color=GREEN, fill_opacity=1, fill_color=BLUE_C,
+ stroke_width=3,
+ stroke_color=GREEN,
+ fill_opacity=1,
+ fill_color=BLUE_C,
)
circle.replace(self)
self.add_to_back(circle)
@@ -605,8 +612,18 @@ class Logo(VMobject):
"outer_radius": 2.0,
"iris_background_blue": "#74C0E3",
"iris_background_brown": "#8C6239",
- "blue_spike_colors": ["#528EA3", "#3E6576", "#224C5B", BLACK,],
- "brown_spike_colors": ["#754C24", "#603813", "#42210b", BLACK,],
+ "blue_spike_colors": [
+ "#528EA3",
+ "#3E6576",
+ "#224C5B",
+ BLACK,
+ ],
+ "brown_spike_colors": [
+ "#754C24",
+ "#603813",
+ "#42210b",
+ BLACK,
+ ],
"n_spike_layers": 4,
"n_spikes": 28,
"spike_angle": TAU / 28,
@@ -637,13 +654,19 @@ class Logo(VMobject):
fill_opacity=1,
stroke_width=0,
)
- self.iris_background = VGroup(blue_iris_back, brown_iris_back,)
+ self.iris_background = VGroup(
+ blue_iris_back,
+ brown_iris_back,
+ )
self.add(self.iris_background)
def add_spikes(self):
layers = VGroup()
radii = np.linspace(
- self.outer_radius, self.pupil_radius, self.n_spike_layers, endpoint=False,
+ self.outer_radius,
+ self.pupil_radius,
+ self.n_spike_layers,
+ endpoint=False,
)
radii[:2] = radii[1::-1] # Swap first two
if self.n_spike_layers > 2:
@@ -660,7 +683,10 @@ class Logo(VMobject):
fill_opacity=1,
stroke_width=0,
)
- for vertex3 in (half_base * LEFT, ORIGIN,)
+ for vertex3 in (
+ half_base * LEFT,
+ ORIGIN,
+ )
]
left_half_triangle = right_half_triangle.copy()
left_half_triangle.flip(UP, about_point=ORIGIN)
@@ -678,9 +704,13 @@ class Logo(VMobject):
else:
half_spikes = [
right_half_triangle.copy(),
- left_half_triangle.copy().rotate(90 * DEGREES, about_point=ORIGIN,),
+ left_half_triangle.copy().rotate(
+ 90 * DEGREES,
+ about_point=ORIGIN,
+ ),
right_half_triangle.copy().rotate(
- 90 * DEGREES, about_point=ORIGIN,
+ 90 * DEGREES,
+ about_point=ORIGIN,
),
left_half_triangle.copy(),
]
@@ -872,11 +902,25 @@ class PlayingCard(VGroup):
def get_number_design(self, value, symbol):
num = int(value)
- n_rows = {2: 2, 3: 3, 4: 2, 5: 2, 6: 3, 7: 3, 8: 3, 9: 4, 10: 4,}[num]
+ n_rows = {
+ 2: 2,
+ 3: 3,
+ 4: 2,
+ 5: 2,
+ 6: 3,
+ 7: 3,
+ 8: 3,
+ 9: 4,
+ 10: 4,
+ }[num]
n_cols = 1 if num in [2, 3] else 2
- insertion_indices = {5: [0], 7: [0], 8: [0, 1], 9: [1], 10: [0, 2],}.get(
- num, []
- )
+ insertion_indices = {
+ 5: [0],
+ 7: [0],
+ 8: [0, 1],
+ 9: [1],
+ 10: [0, 2],
+ }.get(num, [])
top = self.get_top() + symbol.get_height() * DOWN
bottom = self.get_bottom() + symbol.get_height() * UP
@@ -905,7 +949,7 @@ class PlayingCard(VGroup):
return VGroup()
def get_corner_numbers(self, value, symbol):
- value_mob = TextMobject(value)
+ value_mob = Tex(value)
width = self.get_width() / self.card_width_to_corner_num_width
height = self.get_height() / self.card_height_to_corner_num_height
value_mob.set_width(width)
diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.py
index dc265e394..a82c639ac 100644
--- a/manim/mobject/svg/tex_mobject.py
+++ b/manim/mobject/svg/tex_mobject.py
@@ -1,18 +1,20 @@
__all__ = [
"TexSymbol",
- "SingleStringTexMobject",
- "TexMobject",
- "TextMobject",
+ "SingleStringMathTex",
+ "MathTex",
+ "Tex",
"BulletedList",
- "TexMobjectFromPresetString",
+ "MathTexFromPresetString",
"Title",
+ "TexMobject",
+ "TextMobject",
]
from functools import reduce
import operator as op
-from ... import config
+from ... import config, logger
from ...constants import *
from ...mobject.geometry import Line
from ...mobject.svg.svg_mobject import SVGMobject
@@ -32,7 +34,7 @@ class TexSymbol(VMobjectFromSVGPathstring):
pass
-class SingleStringTexMobject(SVGMobject):
+class SingleStringMathTex(SVGMobject):
CONFIG = {
"stroke_width": 0,
"fill_opacity": 1.0,
@@ -113,7 +115,7 @@ class SingleStringTexMobject(SVGMobject):
def remove_stray_braces(self, tex):
"""
- Makes TexMobject resiliant to unmatched { at start
+ Makes MathTex resilient to unmatched { at start
"""
# "\{" does not count (it's a brace literal), but "\\{" counts (it's a new line and then brace)
num_lefts = tex.count("{") - tex.count("\\{") + tex.count("\\\\{")
@@ -139,7 +141,7 @@ class SingleStringTexMobject(SVGMobject):
return self
-class TexMobject(SingleStringTexMobject):
+class MathTex(SingleStringMathTex):
CONFIG = {
"arg_separator": " ",
"substrings_to_isolate": [],
@@ -150,7 +152,7 @@ class TexMobject(SingleStringTexMobject):
digest_config(self, kwargs)
tex_strings = self.break_up_tex_strings(tex_strings)
self.tex_strings = tex_strings
- SingleStringTexMobject.__init__(
+ SingleStringMathTex.__init__(
self, self.arg_separator.join(tex_strings), **kwargs
)
self.break_up_by_substrings()
@@ -183,13 +185,13 @@ class TexMobject(SingleStringTexMobject):
config = dict(self.CONFIG)
config["alignment"] = ""
for tex_string in self.tex_strings:
- sub_tex_mob = SingleStringTexMobject(tex_string, **config)
+ sub_tex_mob = SingleStringMathTex(tex_string, **config)
num_submobs = len(sub_tex_mob.submobjects)
new_index = curr_index + num_submobs
if num_submobs == 0:
# For cases like empty tex_strings, we want the corresponing
- # part of the whole TexMobject to be a VectorizedPoint
- # positioned in the right part of the TexMobject
+ # part of the whole MathTex to be a VectorizedPoint
+ # positioned in the right part of the MathTex
sub_tex_mob.submobjects = [VectorizedPoint()]
last_submob_index = min(curr_index, len(self.submobjects) - 1)
sub_tex_mob.move_to(self.submobjects[last_submob_index], RIGHT)
@@ -237,7 +239,7 @@ class TexMobject(SingleStringTexMobject):
def index_of_part(self, part):
split_self = self.split()
if part not in split_self:
- raise Exception("Trying to get index of part not in TexMobject")
+ raise Exception("Trying to get index of part not in MathTex")
return split_self.index(part)
def index_of_part_by_tex(self, tex, **kwargs):
@@ -248,7 +250,7 @@ class TexMobject(SingleStringTexMobject):
self.submobjects.sort(key=lambda m: m.get_tex_string())
-class TextMobject(TexMobject):
+class Tex(MathTex):
CONFIG = {
"alignment": "\\centering",
"arg_separator": "",
@@ -256,7 +258,7 @@ class TextMobject(TexMobject):
}
-class BulletedList(TextMobject):
+class BulletedList(Tex):
CONFIG = {
"buff": MED_LARGE_BUFF,
"dot_scale_factor": 2,
@@ -266,9 +268,9 @@ class BulletedList(TextMobject):
def __init__(self, *items, **kwargs):
line_separated_items = [s + "\\\\" for s in items]
- TextMobject.__init__(self, *line_separated_items, **kwargs)
+ Tex.__init__(self, *line_separated_items, **kwargs)
for part in self:
- dot = TexMobject("\\cdot").scale(self.dot_scale_factor)
+ dot = MathTex("\\cdot").scale(self.dot_scale_factor)
dot.next_to(part[0], LEFT, SMALL_BUFF)
part.add_to_back(dot)
self.arrange(DOWN, aligned_edge=LEFT, buff=self.buff)
@@ -288,7 +290,7 @@ class BulletedList(TextMobject):
other_part.set_fill(opacity=opacity)
-class TexMobjectFromPresetString(TexMobject):
+class MathTexFromPresetString(MathTex):
CONFIG = {
# To be filled by subclasses
"tex": None,
@@ -297,11 +299,11 @@ class TexMobjectFromPresetString(TexMobject):
def __init__(self, **kwargs):
digest_config(self, kwargs)
- TexMobject.__init__(self, self.tex, **kwargs)
+ MathTex.__init__(self, self.tex, **kwargs)
self.set_color(self.color)
-class Title(TextMobject):
+class Title(Tex):
CONFIG = {
"scale_factor": 1,
"include_underline": True,
@@ -312,7 +314,7 @@ class Title(TextMobject):
}
def __init__(self, *text_parts, **kwargs):
- TextMobject.__init__(self, *text_parts, **kwargs)
+ Tex.__init__(self, *text_parts, **kwargs)
self.scale(self.scale_factor)
self.to_edge(UP)
if self.include_underline:
@@ -324,3 +326,21 @@ class Title(TextMobject):
underline.set_width(self.underline_width)
self.add(underline)
self.underline = underline
+
+
+class TexMobject(MathTex):
+ def __init__(self, *tex_strings, **kwargs):
+ logger.warning(
+ "TexMobject has been deprecated (due to its confusing name)"
+ "in favour of MathTex. Please use MathTex instead!"
+ )
+ MathTex.__init__(self, *tex_strings, **kwargs)
+
+
+class TextMobject(Tex):
+ def __init__(self, *text_parts, **kwargs):
+ logger.warning(
+ "TextMobject has been deprecated (due to its confusing name)"
+ "in favour of Tex. Please use Tex instead!"
+ )
+ Tex.__init__(self, *text_parts, **kwargs)
diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py
index 1d93ee57c..dfc5ca409 100644
--- a/manim/mobject/types/vectorized_mobject.py
+++ b/manim/mobject/types/vectorized_mobject.py
@@ -80,7 +80,8 @@ class VMobject(Mobject):
# Colors
def init_colors(self):
self.set_fill(
- color=self.fill_color or self.color, opacity=self.fill_opacity,
+ color=self.fill_color or self.color,
+ opacity=self.fill_opacity,
)
self.set_stroke(
color=self.stroke_color or self.color,
@@ -93,7 +94,8 @@ class VMobject(Mobject):
opacity=self.background_stroke_opacity,
)
self.set_sheen(
- factor=self.sheen_factor, direction=self.sheen_direction,
+ factor=self.sheen_factor,
+ direction=self.sheen_direction,
)
return self
@@ -201,7 +203,9 @@ class VMobject(Mobject):
)
if sheen_factor:
self.set_sheen(
- factor=sheen_factor, direction=sheen_direction, family=family,
+ factor=sheen_factor,
+ direction=sheen_direction,
+ family=family,
)
if background_image_file:
self.color_using_background_image(background_image_file)
@@ -251,13 +255,16 @@ class VMobject(Mobject):
def fade(self, darkness=0.5, family=True):
factor = 1.0 - darkness
self.set_fill(
- opacity=factor * self.get_fill_opacity(), family=False,
+ opacity=factor * self.get_fill_opacity(),
+ family=False,
)
self.set_stroke(
- opacity=factor * self.get_stroke_opacity(), family=False,
+ opacity=factor * self.get_stroke_opacity(),
+ family=False,
)
self.set_background_stroke(
- opacity=factor * self.get_stroke_opacity(background=True), family=False,
+ opacity=factor * self.get_stroke_opacity(background=True),
+ family=False,
)
super().fade(darkness, family)
return self
@@ -673,7 +680,14 @@ class VMobject(Mobject):
if self.points.shape[0] == 1:
return self.points
return np.array(
- list(it.chain(*zip(self.get_start_anchors(), self.get_end_anchors(),)))
+ list(
+ it.chain(
+ *zip(
+ self.get_start_anchors(),
+ self.get_end_anchors(),
+ )
+ )
+ )
)
def get_points_defining_boundary(self):
@@ -1068,9 +1082,9 @@ class VDict(VMobject):
mob = value
if self.show_keys:
# This import is here and not at the top to avoid circular import
- from ...mobject.svg.tex_mobject import TextMobject
+ from ...mobject.svg.tex_mobject import Tex
- key_text = TextMobject(str(key)).next_to(value, LEFT)
+ key_text = Tex(str(key)).next_to(value, LEFT)
mob.add(key_text)
self.submob_dict[key] = mob
diff --git a/manim/scene/graph_scene.py b/manim/scene/graph_scene.py
index 68789b5df..2865bde45 100644
--- a/manim/scene/graph_scene.py
+++ b/manim/scene/graph_scene.py
@@ -13,8 +13,8 @@ from ..mobject.geometry import Line
from ..mobject.geometry import Rectangle
from ..mobject.geometry import RegularPolygon
from ..mobject.number_line import NumberLine
-from ..mobject.svg.tex_mobject import TexMobject
-from ..mobject.svg.tex_mobject import TextMobject
+from ..mobject.svg.tex_mobject import MathTex
+from ..mobject.svg.tex_mobject import Tex
from ..mobject.types.vectorized_mobject import VGroup
from ..mobject.types.vectorized_mobject import VectorizedPoint
from ..scene.scene import Scene
@@ -113,7 +113,7 @@ class GraphScene(Scene):
self.x_labeled_nums = [x for x in self.x_labeled_nums if x != 0]
x_axis.add_numbers(*self.x_labeled_nums)
if self.x_axis_label:
- x_label = TextMobject(self.x_axis_label)
+ x_label = Tex(self.x_axis_label)
x_label.next_to(
x_axis.get_tips() if self.include_tip else x_axis.get_tick_marks(),
self.x_label_position,
@@ -156,7 +156,7 @@ class GraphScene(Scene):
self.y_labeled_nums = [y for y in self.y_labeled_nums if y != 0]
y_axis.add_numbers(*self.y_labeled_nums)
if self.y_axis_label:
- y_label = TextMobject(self.y_axis_label)
+ y_label = Tex(self.y_axis_label)
y_label.next_to(
y_axis.get_corner(self.y_label_position),
self.y_label_position,
@@ -412,11 +412,11 @@ class GraphScene(Scene):
Returns
-------
- TexMobject
+ :class:`~.MathTex`
The LaTeX of the passed 'label' parameter
"""
- label = TexMobject(label)
+ label = MathTex(label)
color = color or graph.get_color()
label.set_color(color)
if x_val is None:
@@ -818,11 +818,11 @@ class GraphScene(Scene):
labels = VGroup()
if dx_label is not None:
- group.dx_label = TexMobject(dx_label)
+ group.dx_label = MathTex(dx_label)
labels.add(group.dx_label)
group.add(group.dx_label)
if df_label is not None:
- group.df_label = TexMobject(df_label)
+ group.df_label = MathTex(df_label)
labels.add(group.df_label)
group.add(group.df_label)
@@ -863,7 +863,7 @@ class GraphScene(Scene):
This method adds to the Scene:
-- a Vertical line from the x-axis to the corresponding point on the graph/curve.
-- a small vertical Triangle whose top point lies on the base of the vertical line
- -- a TexMobject to be a label for the Line and Triangle, at the bottom of the Triangle.
+ -- a MathTex to be a label for the Line and Triangle, at the bottom of the Triangle.
The scene needs to have the graph have the identifier/variable name self.v_graph.
Parameters
@@ -892,9 +892,9 @@ class GraphScene(Scene):
triangle.set_fill(color, 1)
triangle.set_stroke(width=0)
if label is None:
- T_label = TexMobject(self.variable_point_label, fill_color=color)
+ T_label = MathTex(self.variable_point_label, fill_color=color)
else:
- T_label = TexMobject(label, fill_color=color)
+ T_label = MathTex(label, fill_color=color)
T_label.next_to(triangle, DOWN)
v_line = self.get_vertical_line_to_graph(x_val, self.v_graph, color=YELLOW)
diff --git a/manim/scene/vector_space_scene.py b/manim/scene/vector_space_scene.py
index 8d96d3ad6..65bc19eb5 100644
--- a/manim/scene/vector_space_scene.py
+++ b/manim/scene/vector_space_scene.py
@@ -24,8 +24,8 @@ from ..mobject.matrix import Matrix
from ..mobject.matrix import VECTOR_LABEL_SCALE_FACTOR
from ..mobject.matrix import vector_coordinate_label
from ..mobject.mobject import Mobject
-from ..mobject.svg.tex_mobject import TexMobject
-from ..mobject.svg.tex_mobject import TextMobject
+from ..mobject.svg.tex_mobject import MathTex
+from ..mobject.svg.tex_mobject import Tex
from ..mobject.types.vectorized_mobject import VGroup
from ..mobject.types.vectorized_mobject import VMobject
from ..scene.scene import Scene
@@ -227,7 +227,7 @@ class VectorScene(Scene):
**kwargs
Any valid keyword arguments of get_vector_label:
vector,
- label (str,TexMobject)
+ label (str,MathTex)
at_tip (bool=False),
direction (str="left"),
rotate (bool),
@@ -279,13 +279,13 @@ class VectorScene(Scene):
Returns
-------
- TexMobject
- The TexMobject of the label.
+ MathTex
+ The MathTex of the label.
"""
- if not isinstance(label, TexMobject):
+ if not isinstance(label, MathTex):
if len(label) == 1:
label = "\\vec{\\textbf{%s}}" % label
- label = TexMobject(label)
+ label = MathTex(label)
if color is None:
color = vector.get_color()
label.set_color(color)
@@ -318,8 +318,8 @@ class VectorScene(Scene):
vector : Vector
The vector for which the label must be added.
- label : TexMobject, str
- The TexMobject/string of the label.
+ label : MathTex, str
+ The MathTex/string of the label.
animate : bool, optional
Whether or not to animate the labelling w/ Write
@@ -329,8 +329,8 @@ class VectorScene(Scene):
Returns
-------
- TexMobject
- The TexMobject of the label.
+ :class:`~.MathTex`
+ The MathTex of the label.
"""
label = self.get_vector_label(vector, label, **kwargs)
if animate:
@@ -517,9 +517,16 @@ class LinearTransformationScene(VectorScene):
},
"background_plane_kwargs": {
"color": GREY,
- "axis_config": {"stroke_color": LIGHT_GREY,},
- "axis_config": {"color": GREY,},
- "background_line_style": {"stroke_color": GREY, "stroke_width": 1,},
+ "axis_config": {
+ "stroke_color": LIGHT_GREY,
+ },
+ "axis_config": {
+ "color": GREY,
+ },
+ "background_line_style": {
+ "stroke_color": GREY,
+ "stroke_width": 1,
+ },
},
"show_coordinates": False,
"show_basis_vectors": True,
@@ -554,7 +561,8 @@ class LinearTransformationScene(VectorScene):
self.add_transformable_mobject(self.plane)
if self.show_basis_vectors:
self.basis_vectors = self.get_basis_vectors(
- i_hat_color=self.i_hat_color, j_hat_color=self.j_hat_color,
+ i_hat_color=self.i_hat_color,
+ j_hat_color=self.j_hat_color,
)
self.moving_vectors += list(self.basis_vectors)
self.i_hat, self.j_hat = self.basis_vectors
@@ -759,13 +767,13 @@ class LinearTransformationScene(VectorScene):
vector : Vector
The vector for which the label must be added.
- label : TexMobject,str
- The TexMobject/string of the label.
+ label : Union[:class:`~.MathTex`, :class:`str`]
+ The MathTex/string of the label.
- transformation_name : str, TexMobject, optional
+ transformation_name : Union[:class:`str`, :class:`~.MathTex`], optional
The name to give the transformation as a label.
- new_label : TexMobject,str, optional
+ new_label : Union[:class:`str`, :class:`~.MathTex`], optional
What the label should display after a Linear Transformation
**kwargs
@@ -773,8 +781,8 @@ class LinearTransformationScene(VectorScene):
Returns
-------
- TexMobject
- The TexMobject of the label.
+ :class:`~.MathTex`
+ The MathTex of the label.
"""
label_mob = self.label_vector(vector, label, **kwargs)
if new_label:
@@ -799,7 +807,7 @@ class LinearTransformationScene(VectorScene):
Parameters
----------
- title : str,TexMobject,TextMobject
+ title : Union[:class:`str`, :class:`~.MathTex`, :class:`~.Tex`]
What the title should be.
scale_factor : int, float, optional
@@ -814,7 +822,7 @@ class LinearTransformationScene(VectorScene):
The scene with the title added to it.
"""
if not isinstance(title, Mobject):
- title = TextMobject(title).scale(scale_factor)
+ title = Tex(title).scale(scale_factor)
title.to_edge(UP)
title.add_background_rectangle()
if animate:
diff --git a/tests/test_logging/basic_scenes.py b/tests/test_logging/basic_scenes.py
index 5d1ffff5b..09172c3f7 100644
--- a/tests/test_logging/basic_scenes.py
+++ b/tests/test_logging/basic_scenes.py
@@ -18,10 +18,8 @@ class SquareToCircle(Scene):
class WriteStuff(Scene):
def construct(self):
- example_text = TextMobject(
- "This is a some text", tex_to_color_map={"text": YELLOW}
- )
- example_tex = TexMobject(
+ example_text = Tex("This is a some text", tex_to_color_map={"text": YELLOW})
+ example_tex = MathTex(
"\\sum_{k=1}^\\infty {1 \\over k^2} = {\\pi^2 \\over 6}",
)
group = VGroup(example_text, example_tex)