Skip to content

Commit b7eefca

Browse files
Fix incorrect submobject count of multi-part Tex/MathTex mobjects by stopping them from adding empty submobjects (#3423)
* do not add a VectorizedPoint as a submobject if SingleStringMathTex renders to empty SVG * test new behavior * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update tests/module/mobject/text/test_texmobject.py * Update tests/module/mobject/text/test_texmobject.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5193e1c commit b7eefca

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

manim/mobject/text/tex_mobject.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,6 @@ def _break_up_by_substrings(self):
344344
curr_index + num_submobs + len("".join(self.arg_separator.split()))
345345
)
346346
if num_submobs == 0:
347-
# For cases like empty tex_strings, we want the corresponding
348-
# part of the whole MathTex to be a VectorizedPoint
349-
# positioned in the right part of the MathTex
350-
sub_tex_mob.submobjects = [VectorizedPoint()]
351347
last_submob_index = min(curr_index, len(self.submobjects) - 1)
352348
sub_tex_mob.move_to(self.submobjects[last_submob_index], RIGHT)
353349
else:

tests/module/mobject/text/test_texmobject.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pathlib import Path
44

5+
import numpy as np
56
import pytest
67

78
from manim import MathTex, SingleStringMathTex, Tex, TexTemplate, config, tempconfig
@@ -96,6 +97,23 @@ def test_tex_white_space_and_non_whitespace_args():
9697
assert len(tex[3]) == len("".join(str_part_4.split()))
9798

9899

100+
def test_multi_part_tex_with_empty_parts():
101+
"""Check that if a Tex or MathTex Mobject with multiple
102+
string arguments is created where some of the parts render
103+
as empty SVGs, then the number of family members with points
104+
should still be the same as the snipped in one singular part.
105+
"""
106+
tex_parts = ["(-1)", "^{", "0}"]
107+
one_part_fomula = MathTex("".join(tex_parts))
108+
multi_part_formula = MathTex(*tex_parts)
109+
110+
for one_part_glyph, multi_part_glyph in zip(
111+
one_part_fomula.family_members_with_points(),
112+
multi_part_formula.family_members_with_points(),
113+
):
114+
np.testing.assert_allclose(one_part_glyph.points, multi_part_glyph.points)
115+
116+
99117
def test_tex_size():
100118
"""Check that the size of a :class:`Tex` string is not changed."""
101119
text = Tex("what").center()

0 commit comments

Comments
 (0)