A community-maintained Python framework for creating mathematical animations.
Fixed Tex environment doubling braces (#4159)
F. Muenkelcd2a3b92f68a
diff --git a/manim/utils/tex.py b/manim/utils/tex.pyindex 39ef55d8f..50f5f2dfc 100644--- a/manim/utils/tex.py+++ b/manim/utils/tex.py@@ -184,7 +184,7 @@ def _texcode_for_environment(environment: str) -> tuple[str, str]:A pair of strings representing the opening and closing of the tex environment, e.g.``\begin{tabular}{cccl}`` and ``\end{tabular}``"""- environment.removeprefix(r"\begin").removeprefix("{")+ environment = environment.removeprefix(r"\begin").removeprefix("{")# The \begin command takes everything and closes with a bracebegin = r"\begin{" + environmentdiff --git a/tests/module/utils/test_tex.py b/tests/module/utils/test_tex.pyindex 51666168e..ad0093e09 100644--- a/tests/module/utils/test_tex.py+++ b/tests/module/utils/test_tex.py@@ -1,6 +1,6 @@import pytest-from manim.utils.tex import TexTemplate+from manim.utils.tex import TexTemplate, _texcode_for_environmentDEFAULT_BODY = r"""\documentclass[preview]{standalone}\usepackage[english]{babel}@@ -116,3 +116,27 @@ def test_tex_template_fixed_body():match="This TeX template was created with a fixed body, trying to add text the document will have no effect.",):template.add_to_document("dummy")+++def test_texcode_for_environment():+ """Test that the environment is correctly extracted from the input"""+ # environment without arguments+ assert _texcode_for_environment("align*") == (r"\begin{align*}", r"\end{align*}")+ assert _texcode_for_environment("{align*}") == (r"\begin{align*}", r"\end{align*}")+ assert _texcode_for_environment(r"\begin{align*}") == (+ r"\begin{align*}",+ r"\end{align*}",+ )+ # environment with arguments+ assert _texcode_for_environment("{tabular}[t]{cccl}") == (+ r"\begin{tabular}[t]{cccl}",+ r"\end{tabular}",+ )+ assert _texcode_for_environment("tabular}{cccl") == (+ r"\begin{tabular}{cccl}",+ r"\end{tabular}",+ )+ assert _texcode_for_environment(r"\begin{tabular}[t]{cccl}") == (+ r"\begin{tabular}[t]{cccl}",+ r"\end{tabular}",+ )