Skip to content

Commit 7f17bc2

Browse files
cobordismbehackl
andauthored
Use 'center' tex_environment instead of \centering (#567)
* Use 'center' tex_environment instead of \centering * comment * always with the escaping... * Update manim/utils/tex.py Co-authored-by: Benjamin Hackl <[email protected]> * New Changelog for 0.2.0 * formatting * formatting Co-authored-by: Aron Fischer <co-bordism on gitlab> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent acb27db commit 7f17bc2

File tree

4 files changed

+73
-10
lines changed

4 files changed

+73
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ docs/_build/
5858
docs/build/
5959
docs/source/_autosummary/
6060
docs/source/reference/
61+
docs/source/_build/
6162

6263
# PyBuilder
6364
target/

docs/source/changelog.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,30 @@
22
Changelog
33
*********
44

5+
6+
v0.2.0
7+
==================
8+
9+
:Date: TBD
10+
11+
Changes since Manim Community release v0.1.0
12+
13+
14+
15+
Mobjects, Scenes, and Animations
16+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
#. The ``alignment`` attribute to Tex and MathTex has been removed in favour of ``tex_environment``.
19+
20+
21+
22+
23+
24+
25+
26+
527
v0.1.0
6-
======
28+
==================
729

830
:Date: October 21, 2020
931

@@ -20,7 +42,7 @@ Command line
2042
^^^^^^^^^^^^
2143

2244
#. Output of 'manim --help' has been improved
23-
#. Implement logging with the :code:`rich` library and a :code:`logger` object instead of plain ol` prints
45+
#. Implement logging with the :code:`rich` library and a :code:`logger` object instead of plain ol' prints
2446
#. Added a flag :code:`--dry_run`, which doesn’t write any media
2547
#. Allow for running manim with :code:`python3 -m manim`
2648
#. Refactored Tex Template management. You can now use custom templates with command line args using :code:`--tex_template`!
@@ -107,3 +129,6 @@ Other Changes
107129
#. Rename package from manimlib to manim
108130
#. Move all imports to :code:`__init__`, so :code:`from manim import *` replaces :code:`from manimlib.imports import *`
109131
#. Global dir variable handling has been removed. Instead :code:`initialize_directories`, if needed, overrides the values from the cfg files at runtime.
132+
133+
134+

manim/mobject/svg/tex_mobject.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class SingleStringMathTex(SVGMobject):
5757
"should_center": True,
5858
"height": None,
5959
"organize_left_to_right": False,
60-
"alignment": "",
6160
"tex_environment": "align*",
6261
"tex_template": None,
6362
}
@@ -84,7 +83,7 @@ def __repr__(self):
8483
return f"{type(self).__name__}({repr(self.tex_string)})"
8584

8685
def get_modified_expression(self, tex_string):
87-
result = self.alignment + " " + tex_string
86+
result = tex_string
8887
result = result.strip()
8988
result = self.modify_special_strings(result)
9089
return result
@@ -311,9 +310,8 @@ class Tex(MathTex):
311310
"""
312311

313312
CONFIG = {
314-
"alignment": "\\centering",
315313
"arg_separator": "",
316-
"tex_environment": None,
314+
"tex_environment": "center",
317315
}
318316

319317

@@ -322,7 +320,7 @@ class BulletedList(Tex):
322320
"buff": MED_LARGE_BUFF,
323321
"dot_scale_factor": 2,
324322
# Have to include because of handle_multiple_args implementation
325-
"alignment": "",
323+
"tex_environment": None,
326324
}
327325

328326
def __init__(self, *items, **kwargs):

manim/utils/tex.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
import os
10+
import re
1011

1112

1213
class TexTemplate:
@@ -130,6 +131,7 @@ def _rebuild(self):
130131

131132
def add_to_preamble(self, txt, prepend=False):
132133
"""Adds stuff to the TeX template's preamble (e.g. definitions, packages). Text can be inserted at the beginning or at the end of the preamble.
134+
133135
Parameters
134136
----------
135137
txt : :class:`string`
@@ -169,6 +171,44 @@ def get_texcode_for_expression(self, expression):
169171
"""
170172
return self.body.replace(self.placeholder_text, expression)
171173

174+
def _texcode_for_environment(self, environment):
175+
"""Processes the tex_environment string to return the correct ``\\begin{environment}[extra]{extra}`` and
176+
``\\end{environment}`` strings
177+
178+
Parameters
179+
----------
180+
environment : :class:`str`
181+
The tex_environment as a string. Acceptable formats include:
182+
``{align*}``, ``align*``, ``{tabular}[t]{cccl}``, ``tabular}{cccl``, ``\\begin{tabular}[t]{cccl}``.
183+
184+
Returns
185+
-------
186+
Tuple[:class:`str`, :class:`str`]
187+
A pair of strings representing the opening and closing of the tex environment, e.g.
188+
``\\begin{tabular}{cccl}`` and ``\\end{tabular}``
189+
"""
190+
191+
# If the environment starts with \begin, remove it
192+
if environment[0:6] == r"\begin":
193+
environment = environment[6:]
194+
195+
# If environment begins with { strip it
196+
if environment[0] == r"{":
197+
environment = environment[1:]
198+
199+
# The \begin command takes everything and closes with a brace
200+
begin = r"\begin{" + environment
201+
if (
202+
begin[-1] != r"}" and begin[-1] != r"]"
203+
): # If it doesn't end on } or ], assume missing }
204+
begin += r"}"
205+
206+
# While the \end command terminates at the first closing brace
207+
split_at_brace = re.split(r"}", environment, 1)
208+
end = r"\end{" + split_at_brace[0] + r"}"
209+
210+
return begin, end
211+
172212
def get_texcode_for_expression_in_env(self, expression, environment):
173213
"""Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}
174214
@@ -184,8 +224,7 @@ def get_texcode_for_expression_in_env(self, expression, environment):
184224
:class:`str`
185225
LaTeX code based on template, containing the given expression inside its environment, ready for typesetting
186226
"""
187-
begin = r"\begin{" + environment + "}"
188-
end = r"\end{" + environment + "}"
227+
begin, end = self._texcode_for_environment(environment)
189228
return self.body.replace(
190229
self.placeholder_text, "{0}\n{1}\n{2}".format(begin, expression, end)
191230
)
@@ -236,7 +275,7 @@ def _rebuild(self):
236275
with open(self.template_file, "r") as infile:
237276
self.body = infile.read()
238277

239-
def file_not_mutable():
278+
def file_not_mutable(self):
240279
raise Exception("Cannot modify TexTemplate when using a template file.")
241280

242281
def add_to_preamble(self, txt, prepend=False):

0 commit comments

Comments
 (0)