From 93799074c922fd2dc429ba0032c17929069c8c16 Mon Sep 17 00:00:00 2001 From: Henrik Skov Midtiby Date: Wed, 11 Mar 2026 17:00:59 +0100 Subject: [PATCH 1/2] In parsing a string in MathTex let . match newline chars --- manim/mobject/text/tex_mobject.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 8698e024b8..de477b26fc 100644 --- a/manim/mobject/text/tex_mobject.py +++ b/manim/mobject/text/tex_mobject.py @@ -469,7 +469,11 @@ def _locate_first_match( first_match_length = 0 first_match = None for 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 = match first_match_start = len(match.group(1)) From 4a8583285d46f7c72c1803f30acf26256b66bdd4 Mon Sep 17 00:00:00 2001 From: Henrik Skov Midtiby Date: Wed, 11 Mar 2026 19:05:01 +0100 Subject: [PATCH 2/2] Added a unit test to verify that the correct number of submobjects are added by Tex --- tests/module/mobject/text/test_texmobject.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 48297abec6..f32425e81c 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -136,6 +136,17 @@ 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_tex(config): Tex("The horse does not eat cucumber salad.") assert Path(config.media_dir, "Tex", "5384b41741a246bd.svg").exists()