Skip to content

armgit / manim

Public Imported from GitHub
0

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.py
index 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 brace
begin = r"\begin{" + environment
diff --git a/tests/module/utils/test_tex.py b/tests/module/utils/test_tex.py
index 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_environment
DEFAULT_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}",
+ )