From c129a2fbeea7a1c46803be266c47b848551db50b Mon Sep 17 00:00:00 2001 From: Taksh Date: Wed, 8 Jul 2026 16:58:28 +0530 Subject: [PATCH] fix(tex): match substrings_to_isolate across newlines Use re.DOTALL in _locate_first_match so substrings on later lines of multi-line Tex/MathTex strings are isolated again. Fixes #4617 Co-authored-by: Cursor --- manim/mobject/text/tex_mobject.py | 6 +++++- tests/module/mobject/text/test_texmobject.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/manim/mobject/text/tex_mobject.py b/manim/mobject/text/tex_mobject.py index 729fbb158b..62a977274a 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)) diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py index 48297abec6..5e825a6177 100644 --- a/tests/module/mobject/text/test_texmobject.py +++ b/tests/module/mobject/text/test_texmobject.py @@ -335,3 +335,10 @@ 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_locate_first_match_multiline_substring(config) -> None: + unprocessed = "This is a very long string,\n which tests the implementation." + match = MathTex("a")._locate_first_match(["implementation"], unprocessed) + assert match is not None + assert match.group(2) == "implementation"