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"