MCPcopy
hub / github.com/ManimCommunity/manim / _texcode_for_environment

Function _texcode_for_environment

manim/utils/tex.py:171–199  ·  view source on GitHub ↗

r"""Processes the tex_environment string to return the correct ``\begin{environment}[extra]{extra}`` and ``\end{environment}`` strings. Parameters ---------- environment The tex_environment as a string. Acceptable formats include: ``{align*}``, ``align*``, ``{tabular

(environment: str)

Source from the content-addressed store, hash-verified

169
170
171def _texcode_for_environment(environment: str) -> tuple[str, str]:
172 r"""Processes the tex_environment string to return the correct ``\begin{environment}[extra]{extra}`` and
173 ``\end{environment}`` strings.
174
175 Parameters
176 ----------
177 environment
178 The tex_environment as a string. Acceptable formats include:
179 ``{align*}``, ``align*``, ``{tabular}[t]{cccl}``, ``tabular}{cccl``, ``\begin{tabular}[t]{cccl}``.
180
181 Returns
182 -------
183 Tuple[:class:`str`, :class:`str`]
184 A pair of strings representing the opening and closing of the tex environment, e.g.
185 ``\begin{tabular}{cccl}`` and ``\end{tabular}``
186 """
187 environment = environment.removeprefix(r"\begin").removeprefix("{")
188
189 # The \begin command takes everything and closes with a brace
190 begin = r"\begin{" + environment
191 # If it doesn't end on } or ], assume missing }
192 if not begin.endswith(("}", "]")):
193 begin += "}"
194
195 # While the \end command terminates at the first closing brace
196 split_at_brace = re.split("}", environment, maxsplit=1)
197 end = r"\end{" + split_at_brace[0] + "}"
198
199 return begin, end

Calls 1

splitMethod · 0.45

Tested by 1