Replace Tex and MTex throughout library

This commit is contained in:
Grant Sanderson 2022-12-20 15:22:34 -08:00
parent 0d525baf29
commit 6d5b980d4a
7 changed files with 41 additions and 39 deletions

View file

@ -60,10 +60,10 @@ class Thumbnail(GraphScene):
triangle.scale(0.1) triangle.scale(0.1)
# #
x_label_p1 = Tex("a") x_label_p1 = MTex("a")
output_label_p1 = Tex("f(a)") output_label_p1 = MTex("f(a)")
x_label_p2 = Tex("b") x_label_p2 = MTex("b")
output_label_p2 = Tex("f(b)") output_label_p2 = MTex("f(b)")
v_line_p1 = get_v_line(input_tracker_p1) v_line_p1 = get_v_line(input_tracker_p1)
v_line_p2 = get_v_line(input_tracker_p2) v_line_p2 = get_v_line(input_tracker_p2)
h_line_p1 = get_h_line(input_tracker_p1) h_line_p1 = get_h_line(input_tracker_p1)

View file

@ -18,7 +18,7 @@ from manimlib.mobject.geometry import DashedLine
from manimlib.mobject.geometry import Line from manimlib.mobject.geometry import Line
from manimlib.mobject.geometry import Rectangle from manimlib.mobject.geometry import Rectangle
from manimlib.mobject.number_line import NumberLine from manimlib.mobject.number_line import NumberLine
from manimlib.mobject.svg.tex_mobject import Tex from manimlib.mobject.svg.mtex_mobject import MTex
from manimlib.mobject.types.dot_cloud import DotCloud from manimlib.mobject.types.dot_cloud import DotCloud
from manimlib.mobject.types.surface import ParametricSurface from manimlib.mobject.types.surface import ParametricSurface
from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.mobject.types.vectorized_mobject import VGroup
@ -105,7 +105,7 @@ class CoordinateSystem(ABC):
edge: Vect3 = RIGHT, edge: Vect3 = RIGHT,
direction: Vect3 = DL, direction: Vect3 = DL,
**kwargs **kwargs
) -> Tex: ) -> MTex:
return self.get_axis_label( return self.get_axis_label(
label_tex, self.get_x_axis(), label_tex, self.get_x_axis(),
edge, direction, **kwargs edge, direction, **kwargs
@ -117,7 +117,7 @@ class CoordinateSystem(ABC):
edge: Vect3 = UP, edge: Vect3 = UP,
direction: Vect3 = DR, direction: Vect3 = DR,
**kwargs **kwargs
) -> Tex: ) -> MTex:
return self.get_axis_label( return self.get_axis_label(
label_tex, self.get_y_axis(), label_tex, self.get_y_axis(),
edge, direction, **kwargs edge, direction, **kwargs
@ -130,8 +130,8 @@ class CoordinateSystem(ABC):
edge: Vect3, edge: Vect3,
direction: Vect3, direction: Vect3,
buff: float = MED_SMALL_BUFF buff: float = MED_SMALL_BUFF
) -> Tex: ) -> MTex:
label = Tex(label_tex) label = MTex(label_tex)
label.next_to( label.next_to(
axis.get_edge_center(edge), direction, axis.get_edge_center(edge), direction,
buff=buff buff=buff
@ -268,9 +268,9 @@ class CoordinateSystem(ABC):
direction: Vect3 = RIGHT, direction: Vect3 = RIGHT,
buff: float = MED_SMALL_BUFF, buff: float = MED_SMALL_BUFF,
color: ManimColor | None = None color: ManimColor | None = None
) -> Tex | Mobject: ) -> MTex | Mobject:
if isinstance(label, str): if isinstance(label, str):
label = Tex(label) label = MTex(label)
if color is None: if color is None:
label.match_color(graph) label.match_color(graph)
if x is None: if x is None:
@ -537,7 +537,7 @@ class ThreeDAxes(Axes):
def add_axis_labels(self, x_tex="x", y_tex="y", z_tex="z", font_size=24, buff=0.2): def add_axis_labels(self, x_tex="x", y_tex="y", z_tex="z", font_size=24, buff=0.2):
x_label, y_label, z_label = labels = VGroup(*( x_label, y_label, z_label = labels = VGroup(*(
Tex(tex, font_size=font_size) MTex(tex, font_size=font_size)
for tex in [x_tex, y_tex, z_tex] for tex in [x_tex, y_tex, z_tex]
)) ))
z_label.rotate(PI / 2, RIGHT) z_label.rotate(PI / 2, RIGHT)
@ -697,6 +697,7 @@ class ComplexPlane(NumberPlane):
self, self,
numbers: list[complex] | None = None, numbers: list[complex] | None = None,
skip_first: bool = True, skip_first: bool = True,
font_size: int = 36,
**kwargs **kwargs
): ):
if numbers is None: if numbers is None:
@ -712,7 +713,7 @@ class ComplexPlane(NumberPlane):
else: else:
axis = self.get_x_axis() axis = self.get_x_axis()
value = z.real value = z.real
number_mob = axis.get_number_mobject(value, **kwargs) number_mob = axis.get_number_mobject(value, font_size=font_size, **kwargs)
# For -i, remove the "1" # For -i, remove the "1"
if z.imag == -1: if z.imag == -1:
number_mob.remove(number_mob[1]) number_mob.remove(number_mob[1])

View file

@ -10,8 +10,8 @@ from manimlib.constants import WHITE
from manimlib.mobject.numbers import DecimalNumber from manimlib.mobject.numbers import DecimalNumber
from manimlib.mobject.numbers import Integer from manimlib.mobject.numbers import Integer
from manimlib.mobject.shape_matchers import BackgroundRectangle from manimlib.mobject.shape_matchers import BackgroundRectangle
from manimlib.mobject.svg.tex_mobject import Tex from manimlib.mobject.svg.mtex_mobject import MTex
from manimlib.mobject.svg.tex_mobject import TexText from manimlib.mobject.svg.mtex_mobject import MTexText
from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.mobject.types.vectorized_mobject import VGroup
from manimlib.mobject.types.vectorized_mobject import VMobject from manimlib.mobject.types.vectorized_mobject import VMobject
@ -41,8 +41,8 @@ def matrix_to_tex_string(matrix: npt.ArrayLike) -> str:
return prefix + R" \\ ".join(rows) + suffix return prefix + R" \\ ".join(rows) + suffix
def matrix_to_mobject(matrix: npt.ArrayLike) -> Tex: def matrix_to_mobject(matrix: npt.ArrayLike) -> MTex:
return Tex(matrix_to_tex_string(matrix)) return MTex(matrix_to_tex_string(matrix))
def vector_coordinate_label( def vector_coordinate_label(
@ -109,7 +109,7 @@ class Matrix(VMobject):
def element_to_mobject(self, element: str | float | VMobject, **config) -> VMobject: def element_to_mobject(self, element: str | float | VMobject, **config) -> VMobject:
if isinstance(element, VMobject): if isinstance(element, VMobject):
return element return element
return Tex(str(element), **config) return MTex(str(element), **config)
def matrix_to_mob_matrix( def matrix_to_mob_matrix(
self, self,
@ -142,11 +142,11 @@ class Matrix(VMobject):
def add_brackets(self, v_buff: float, h_buff: float): def add_brackets(self, v_buff: float, h_buff: float):
height = len(self.mob_matrix) height = len(self.mob_matrix)
brackets = Tex("".join(( brackets = MTex("".join((
R"\left[\begin{array}{c}", R"\left[\begin{array}{c}",
*height * [R"\quad \\"], *height * [R"\quad \\"],
R"\end{array}\right]", R"\end{array}\right]",
)))[0] )))
brackets.set_height(self.get_height() + v_buff) brackets.set_height(self.get_height() + v_buff)
l_bracket = brackets[:len(brackets) // 2] l_bracket = brackets[:len(brackets) // 2]
r_bracket = brackets[len(brackets) // 2:] r_bracket = brackets[len(brackets) // 2:]
@ -219,22 +219,22 @@ def get_det_text(
background_rect: bool = False, background_rect: bool = False,
initial_scale_factor: int = 2 initial_scale_factor: int = 2
) -> VGroup: ) -> VGroup:
parens = Tex("(", ")") parens = MTex("()")
parens.scale(initial_scale_factor) parens.scale(initial_scale_factor)
parens.stretch_to_fit_height(matrix.get_height()) parens.stretch_to_fit_height(matrix.get_height())
l_paren, r_paren = parens.split() l_paren, r_paren = parens.split()
l_paren.next_to(matrix, LEFT, buff=0.1) l_paren.next_to(matrix, LEFT, buff=0.1)
r_paren.next_to(matrix, RIGHT, buff=0.1) r_paren.next_to(matrix, RIGHT, buff=0.1)
det = TexText("det") det = MTexText("det")
det.scale(initial_scale_factor) det.scale(initial_scale_factor)
det.next_to(l_paren, LEFT, buff=0.1) det.next_to(l_paren, LEFT, buff=0.1)
if background_rect: if background_rect:
det.add_background_rectangle() det.add_background_rectangle()
det_text = VGroup(det, l_paren, r_paren) det_text = VGroup(det, l_paren, r_paren)
if determinant is not None: if determinant is not None:
eq = Tex("=") eq = MTex("=")
eq.next_to(r_paren, RIGHT, buff=0.1) eq.next_to(r_paren, RIGHT, buff=0.1)
result = Tex(str(determinant)) result = MTex(str(determinant))
result.next_to(eq, RIGHT, buff=0.2) result.next_to(eq, RIGHT, buff=0.2)
det_text.add(eq, result) det_text.add(eq, result)
return det_text return det_text

View file

@ -9,7 +9,7 @@ from manimlib.mobject.geometry import Line
from manimlib.mobject.geometry import Rectangle from manimlib.mobject.geometry import Rectangle
from manimlib.mobject.mobject import Mobject from manimlib.mobject.mobject import Mobject
from manimlib.mobject.svg.brace import Brace from manimlib.mobject.svg.brace import Brace
from manimlib.mobject.svg.tex_mobject import Tex from manimlib.mobject.svg.mtex_mobject import MTex
from manimlib.mobject.svg.tex_mobject import TexText from manimlib.mobject.svg.tex_mobject import TexText
from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.mobject.types.vectorized_mobject import VGroup
from manimlib.utils.color import color_gradient from manimlib.utils.color import color_gradient
@ -132,7 +132,7 @@ class SampleSpace(Rectangle):
if isinstance(label, Mobject): if isinstance(label, Mobject):
label_mob = label label_mob = label
else: else:
label_mob = Tex(label) label_mob = MTex(label)
label_mob.scale(self.default_label_scale_val) label_mob.scale(self.default_label_scale_val)
label_mob.next_to(brace, direction, buff) label_mob.next_to(brace, direction, buff)
@ -266,7 +266,7 @@ class BarChart(VGroup):
if self.label_y_axis: if self.label_y_axis:
labels = VGroup() labels = VGroup()
for y_tick, value in zip(y_ticks, values): for y_tick, value in zip(y_ticks, values):
label = Tex(str(np.round(value, 2))) label = MTex(str(np.round(value, 2)))
label.set_height(self.y_axis_label_height) label.set_height(self.y_axis_label_height)
label.next_to(y_tick, LEFT, SMALL_BUFF) label.next_to(y_tick, LEFT, SMALL_BUFF)
labels.add(label) labels.add(label)
@ -289,7 +289,7 @@ class BarChart(VGroup):
bar_labels = VGroup() bar_labels = VGroup()
for bar, name in zip(bars, self.bar_names): for bar, name in zip(bars, self.bar_names):
label = Tex(str(name)) label = MTex(str(name))
label.scale(self.bar_label_scale_val) label.scale(self.bar_label_scale_val)
label.next_to(bar, DOWN, SMALL_BUFF) label.next_to(bar, DOWN, SMALL_BUFF)
bar_labels.add(label) bar_labels.add(label)

View file

@ -12,7 +12,7 @@ from manimlib.animation.composition import AnimationGroup
from manimlib.animation.fading import FadeIn from manimlib.animation.fading import FadeIn
from manimlib.animation.growing import GrowFromCenter from manimlib.animation.growing import GrowFromCenter
from manimlib.mobject.svg.tex_mobject import SingleStringTex from manimlib.mobject.svg.tex_mobject import SingleStringTex
from manimlib.mobject.svg.tex_mobject import Tex from manimlib.mobject.svg.mtex_mobject import MTex
from manimlib.mobject.svg.tex_mobject import TexText from manimlib.mobject.svg.tex_mobject import TexText
from manimlib.mobject.svg.text_mobject import Text from manimlib.mobject.svg.text_mobject import Text
from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.mobject.types.vectorized_mobject import VGroup
@ -92,8 +92,8 @@ class Brace(SingleStringTex):
self.put_at_tip(text_mob, buff=buff) self.put_at_tip(text_mob, buff=buff)
return text_mob return text_mob
def get_tex(self, *tex: str, **kwargs) -> Tex: def get_tex(self, *tex: str, **kwargs) -> MTex:
tex_mob = Tex(*tex) tex_mob = MTex(*tex)
self.put_at_tip(tex_mob, **kwargs) self.put_at_tip(tex_mob, **kwargs)
return tex_mob return tex_mob
@ -109,7 +109,7 @@ class Brace(SingleStringTex):
class BraceLabel(VMobject): class BraceLabel(VMobject):
label_constructor: type = Tex label_constructor: type = MTex
def __init__( def __init__(
self, self,

View file

@ -42,9 +42,10 @@ from manimlib.mobject.geometry import Polygon
from manimlib.mobject.geometry import Rectangle from manimlib.mobject.geometry import Rectangle
from manimlib.mobject.geometry import Square from manimlib.mobject.geometry import Square
from manimlib.mobject.mobject import Mobject from manimlib.mobject.mobject import Mobject
from manimlib.mobject.numbers import Integer
from manimlib.mobject.svg.svg_mobject import SVGMobject from manimlib.mobject.svg.svg_mobject import SVGMobject
from manimlib.mobject.svg.tex_mobject import Tex from manimlib.mobject.svg.mtex_mobject import MTex
from manimlib.mobject.svg.tex_mobject import TexText from manimlib.mobject.svg.mtex_mobject import MTexText
from manimlib.mobject.svg.special_tex import TexTextFromPresetString from manimlib.mobject.svg.special_tex import TexTextFromPresetString
from manimlib.mobject.three_dimensions import Prismify from manimlib.mobject.three_dimensions import Prismify
from manimlib.mobject.three_dimensions import VCube from manimlib.mobject.three_dimensions import VCube
@ -125,7 +126,7 @@ class Speedometer(VMobject):
for index, angle in enumerate(tick_angle_range): for index, angle in enumerate(tick_angle_range):
vect = rotate_vector(RIGHT, angle) vect = rotate_vector(RIGHT, angle)
tick = Line((1 - tick_length) * vect, vect) tick = Line((1 - tick_length) * vect, vect)
label = Tex(str(10 * index)) label = Integer(10 * index)
label.set_height(tick_length) label.set_height(tick_length)
label.shift((1 + tick_length) * vect) label.shift((1 + tick_length) * vect)
self.add(tick, label) self.add(tick, label)
@ -426,7 +427,7 @@ class Bubble(SVGMobject):
return self.content return self.content
def write(self, *text): def write(self, *text):
self.add_content(TexText(*text)) self.add_content(MTexText(*text))
return self return self
def resize_to_content(self, buff=0.75): def resize_to_content(self, buff=0.75):

View file

@ -17,7 +17,7 @@ from manimlib.mobject.geometry import Square
from manimlib.mobject.mobject import Group from manimlib.mobject.mobject import Group
from manimlib.mobject.mobject import Mobject from manimlib.mobject.mobject import Mobject
from manimlib.mobject.numbers import DecimalNumber from manimlib.mobject.numbers import DecimalNumber
from manimlib.mobject.svg.tex_mobject import Tex from manimlib.mobject.svg.mtex_mobject import MTex
from manimlib.mobject.svg.text_mobject import Text from manimlib.mobject.svg.text_mobject import Text
from manimlib.mobject.types.dot_cloud import DotCloud from manimlib.mobject.types.dot_cloud import DotCloud
from manimlib.mobject.types.vectorized_mobject import VGroup from manimlib.mobject.types.vectorized_mobject import VGroup
@ -61,7 +61,7 @@ class InteractiveScene(Scene):
Command + 'c' copies the ids of selections to clipboard Command + 'c' copies the ids of selections to clipboard
Command + 'v' will paste either: Command + 'v' will paste either:
- The copied mobject - The copied mobject
- A Tex mobject based on copied LaTeX - A MTex mobject based on copied LaTeX
- A Text mobject based on copied Text - A Text mobject based on copied Text
Command + 'z' restores selection back to its original state Command + 'z' restores selection back to its original state
Command + 's' saves the selected mobjects to file Command + 's' saves the selected mobjects to file
@ -358,7 +358,7 @@ class InteractiveScene(Scene):
# Otherwise, treat as tex or text # Otherwise, treat as tex or text
if set("\\^=+").intersection(clipboard_str): # Proxy to text for LaTeX if set("\\^=+").intersection(clipboard_str): # Proxy to text for LaTeX
try: try:
new_mob = Tex(clipboard_str) new_mob = MTex(clipboard_str)
except LatexError: except LatexError:
return return
else: else: