A community-maintained Python framework for creating mathematical animations.
Fix indexing for non-whitespace tex arg separator (#1596)
Ryan McCauley9e8ba2d51990
diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.pyindex 6ef4c49e3..52dedc9b9 100644--- a/manim/mobject/svg/tex_mobject.py+++ b/manim/mobject/svg/tex_mobject.py@@ -501,7 +501,9 @@ class MathTex(SingleStringMathTex):tex_template=self.tex_template,)num_submobs = len(sub_tex_mob.submobjects)- new_index = curr_index + num_submobs+ new_index = (+ curr_index + num_submobs + len("".join(self.arg_separator.split()))+ )if num_submobs == 0:# For cases like empty tex_strings, we want the corresponding# part of the whole MathTex to be a VectorizedPointdiff --git a/tests/test_texmobject.py b/tests/test_texmobject.pyindex e808fab76..c9d7d1b2e 100644--- a/tests/test_texmobject.py+++ b/tests/test_texmobject.py@@ -27,3 +27,48 @@ def test_double_braces_testing(text_input, length_sub):def test_tex():Tex("The horse does not eat cucumber salad.")assert Path(config.media_dir, "Tex", "983949cac5bdd272.svg").exists()+++def test_tex_whitespace_arg():+ """Check that correct number of submobjects are created per string with whitespace separator"""+ separator = "\t"+ str_part_1 = "Hello"+ str_part_2 = "world"+ str_part_3 = "It is"+ str_part_4 = "me!"+ tex = Tex(str_part_1, str_part_2, str_part_3, str_part_4, arg_separator=separator)+ assert len(tex) == 4+ assert len(tex[0]) == len("".join((str_part_1 + separator).split()))+ assert len(tex[1]) == len("".join((str_part_2 + separator).split()))+ assert len(tex[2]) == len("".join((str_part_3 + separator).split()))+ assert len(tex[3]) == len("".join(str_part_4.split()))+++def test_tex_non_whitespace_arg():+ """Check that correct number of submobjects are created per string with non_whitespace characters"""+ separator = ","+ str_part_1 = "Hello"+ str_part_2 = "world"+ str_part_3 = "It is"+ str_part_4 = "me!"+ tex = Tex(str_part_1, str_part_2, str_part_3, str_part_4, arg_separator=separator)+ assert len(tex) == 4+ assert len(tex[0]) == len("".join((str_part_1 + separator).split()))+ assert len(tex[1]) == len("".join((str_part_2 + separator).split()))+ assert len(tex[2]) == len("".join((str_part_3 + separator).split()))+ assert len(tex[3]) == len("".join(str_part_4.split()))+++def test_tex_white_space_and_non_whitespace_args():+ """Check that correct number of submobjects are created per string when mixing characters with whitespace"""+ separator = ", \n . \t\t"+ str_part_1 = "Hello"+ str_part_2 = "world"+ str_part_3 = "It is"+ str_part_4 = "me!"+ tex = Tex(str_part_1, str_part_2, str_part_3, str_part_4, arg_separator=separator)+ assert len(tex) == 4+ assert len(tex[0]) == len("".join((str_part_1 + separator).split()))+ assert len(tex[1]) == len("".join((str_part_2 + separator).split()))+ assert len(tex[2]) == len("".join((str_part_3 + separator).split()))+ assert len(tex[3]) == len("".join(str_part_4.split()))