Skip to content
Closed
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
22 changes: 10 additions & 12 deletions manim/mobject/text/tex_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from manim.constants import *
from manim.mobject.geometry.line import Line
from manim.mobject.svg.svg_mobject import SVGMobject
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.mobject.types.vectorized_mobject import VectorizedPoint, VGroup, VMobject
from manim.utils.tex import TexTemplate
from manim.utils.tex_file_writing import tex_to_svg_file

Expand Down Expand Up @@ -522,17 +522,15 @@ def _break_up_by_substrings(self) -> Self:
of tex_strings)
"""
new_submobjects: list[VMobject] = []
try:
for tex_string, tex_string_id in self._main_matches:
mtp = MathTexPart()
mtp.tex_string = tex_string
mtp.add(*self.id_to_vgroup_dict[tex_string_id].submobjects)
new_submobjects.append(mtp)
except KeyError:
logger.error(
f"MathTex: Could not find SVG group for tex part '{tex_string}' (id: {tex_string_id}). Using fallback to root group."
)
new_submobjects.append(self.id_to_vgroup_dict["root"])
for tex_string, tex_string_id in self._main_matches:
mtp = MathTexPart()
mtp.tex_string = tex_string
vgroup = self.id_to_vgroup_dict.get(tex_string_id)
if vgroup is None or len(vgroup.submobjects) == 0:
mtp.add(VectorizedPoint())
else:
mtp.add(*vgroup.submobjects)
new_submobjects.append(mtp)
self.submobjects = new_submobjects
return self

Expand Down
12 changes: 11 additions & 1 deletion tests/module/mobject/text/test_texmobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pytest

from manim import MathTex, SingleStringMathTex, Tex, TexTemplate, tempconfig
from manim import RIGHT, UP, MathTex, SingleStringMathTex, Tex, TexTemplate, tempconfig


def test_MathTex(config):
Expand Down Expand Up @@ -335,3 +335,13 @@ def test_tex_garbage_collection(tmpdir, monkeypatch, config):

tex_with_log = Tex("Hello World, again!") # 45b4e7819cc20cb1.tex
assert Path("media", "Tex", "45b4e7819cc20cb1.log").exists()


def test_mathtex_bounding_box_stable_after_shift(config):
"""Regression test for https://github.com/ManimCommunity/manim/issues/4643."""
parts = [r"\overrightarrow{", "C", "A", "}", "=", r"\bold{", "m", "}"]
math_tex = MathTex(*parts)
width_before, height_before = math_tex.width, math_tex.height
math_tex.shift(2 * RIGHT + UP)
assert math_tex.width == pytest.approx(width_before, rel=0, abs=1e-6)
assert math_tex.height == pytest.approx(height_before, rel=0, abs=1e-6)
Loading