Skip to content

Commit cd2a3b9

Browse files
authored
Fixed Tex environment doubling braces (#4159)
* Fix environment formating for Tex() mobject * Add test for handling of Tex() environments
1 parent 01fc1ef commit cd2a3b9

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

manim/utils/tex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _texcode_for_environment(environment: str) -> tuple[str, str]:
184184
A pair of strings representing the opening and closing of the tex environment, e.g.
185185
``\begin{tabular}{cccl}`` and ``\end{tabular}``
186186
"""
187-
environment.removeprefix(r"\begin").removeprefix("{")
187+
environment = environment.removeprefix(r"\begin").removeprefix("{")
188188

189189
# The \begin command takes everything and closes with a brace
190190
begin = r"\begin{" + environment

tests/module/utils/test_tex.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from manim.utils.tex import TexTemplate
3+
from manim.utils.tex import TexTemplate, _texcode_for_environment
44

55
DEFAULT_BODY = r"""\documentclass[preview]{standalone}
66
\usepackage[english]{babel}
@@ -116,3 +116,27 @@ def test_tex_template_fixed_body():
116116
match="This TeX template was created with a fixed body, trying to add text the document will have no effect.",
117117
):
118118
template.add_to_document("dummy")
119+
120+
121+
def test_texcode_for_environment():
122+
"""Test that the environment is correctly extracted from the input"""
123+
# environment without arguments
124+
assert _texcode_for_environment("align*") == (r"\begin{align*}", r"\end{align*}")
125+
assert _texcode_for_environment("{align*}") == (r"\begin{align*}", r"\end{align*}")
126+
assert _texcode_for_environment(r"\begin{align*}") == (
127+
r"\begin{align*}",
128+
r"\end{align*}",
129+
)
130+
# environment with arguments
131+
assert _texcode_for_environment("{tabular}[t]{cccl}") == (
132+
r"\begin{tabular}[t]{cccl}",
133+
r"\end{tabular}",
134+
)
135+
assert _texcode_for_environment("tabular}{cccl") == (
136+
r"\begin{tabular}{cccl}",
137+
r"\end{tabular}",
138+
)
139+
assert _texcode_for_environment(r"\begin{tabular}[t]{cccl}") == (
140+
r"\begin{tabular}[t]{cccl}",
141+
r"\end{tabular}",
142+
)

0 commit comments

Comments
 (0)