A community-maintained Python framework for creating mathematical animations.
Let MathTex handle multiline strings (#4634)
Henrik Skov Midtiby3e738121dbe9
diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.pyindex a60ba9d5f..d1c213265 100644--- a/manim/mobject/text/tex_mobject.py+++ b/manim/mobject/text/tex_mobject.py@@ -469,7 +469,11 @@ class MathTex(SingleStringMathTex):first_match_length = 0first_match = Nonefor substring in substrings_to_isolate:- match = re.match(f"(.*?)({re.escape(substring)})(.*)", unprocessed_string)+ match = re.match(+ f"(.*?)({re.escape(substring)})(.*)",+ unprocessed_string,+ flags=re.DOTALL,+ )if match and len(match.group(1)) < first_match_start:first_match = matchfirst_match_start = len(match.group(1))diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.pyindex 48297abec..cf9adbb80 100644--- a/tests/module/mobject/text/test_texmobject.py+++ b/tests/module/mobject/text/test_texmobject.py@@ -136,6 +136,26 @@ def test_split_double_braces(tex_string, expected_segments):assert MathTex._split_double_braces(tex_string) == expected_segments+def test_multiline_tex():+ multiline_string = Tex(+ """This is a very long string,+ which will test how well the new implementation of Tex handles such long strings.""",+ substrings_to_isolate=["This", "implementation"],+ )+ assert len(multiline_string.get_part_by_tex("This").submobjects) == 4+ assert len(multiline_string.get_part_by_tex("implementation").submobjects) == 14+ assert len(multiline_string.submobjects[0]) == 90+++def test_multiline_tex_remainder_is_not_truncated():+ match = MathTex("a")._locate_first_match(+ ["first"],+ "first line\nsecond line",+ )+ assert match is not None+ assert match.groups() == ("", "first", " line\nsecond line")++def test_tex(config):Tex("The horse does not eat cucumber salad.")assert Path(config.media_dir, "Tex", "5384b41741a246bd.svg").exists()