A community-maintained Python framework for creating mathematical animations.
Use 'center' tex_environment instead of \centering (#567)
Aron7f17bc2f133b
diff --git a/.gitignore b/.gitignoreindex f7da3fa52..4606afd95 100644--- a/.gitignore+++ b/.gitignore@@ -58,6 +58,7 @@ docs/_build/docs/build/docs/source/_autosummary/docs/source/reference/+docs/source/_build/# PyBuildertarget/diff --git a/docs/source/changelog.rst b/docs/source/changelog.rstindex 5e16c07ac..50a3ae961 100644--- a/docs/source/changelog.rst+++ b/docs/source/changelog.rst@@ -2,8 +2,30 @@Changelog*********++v0.2.0+==================++:Date: TBD++Changes since Manim Community release v0.1.0++++Mobjects, Scenes, and Animations+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^++#. The ``alignment`` attribute to Tex and MathTex has been removed in favour of ``tex_environment``.++++++++v0.1.0-======+==================:Date: October 21, 2020@@ -20,7 +42,7 @@ Command line^^^^^^^^^^^^#. Output of 'manim --help' has been improved-#. Implement logging with the :code:`rich` library and a :code:`logger` object instead of plain ol` prints+#. Implement logging with the :code:`rich` library and a :code:`logger` object instead of plain ol' prints#. Added a flag :code:`--dry_run`, which doesn’t write any media#. Allow for running manim with :code:`python3 -m manim`#. Refactored Tex Template management. You can now use custom templates with command line args using :code:`--tex_template`!@@ -107,3 +129,6 @@ Other Changes#. Rename package from manimlib to manim#. Move all imports to :code:`__init__`, so :code:`from manim import *` replaces :code:`from manimlib.imports import *`#. Global dir variable handling has been removed. Instead :code:`initialize_directories`, if needed, overrides the values from the cfg files at runtime.+++diff --git a/manim/mobject/svg/tex_mobject.py b/manim/mobject/svg/tex_mobject.pyindex 73bf2418f..f661d0457 100644--- a/manim/mobject/svg/tex_mobject.py+++ b/manim/mobject/svg/tex_mobject.py@@ -57,7 +57,6 @@ class SingleStringMathTex(SVGMobject):"should_center": True,"height": None,"organize_left_to_right": False,- "alignment": "","tex_environment": "align*","tex_template": None,}@@ -84,7 +83,7 @@ class SingleStringMathTex(SVGMobject):return f"{type(self).__name__}({repr(self.tex_string)})"def get_modified_expression(self, tex_string):- result = self.alignment + " " + tex_string+ result = tex_stringresult = result.strip()result = self.modify_special_strings(result)return result@@ -311,9 +310,8 @@ class Tex(MathTex):"""CONFIG = {- "alignment": "\\centering","arg_separator": "",- "tex_environment": None,+ "tex_environment": "center",}@@ -322,7 +320,7 @@ class BulletedList(Tex):"buff": MED_LARGE_BUFF,"dot_scale_factor": 2,# Have to include because of handle_multiple_args implementation- "alignment": "",+ "tex_environment": None,}def __init__(self, *items, **kwargs):diff --git a/manim/utils/tex.py b/manim/utils/tex.pyindex 840c55521..ec87f91f2 100644--- a/manim/utils/tex.py+++ b/manim/utils/tex.py@@ -7,6 +7,7 @@ __all__ = [import os+import reclass TexTemplate:@@ -130,6 +131,7 @@ class TexTemplate:def add_to_preamble(self, txt, prepend=False):"""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.+Parameters----------txt : :class:`string`@@ -169,6 +171,44 @@ class TexTemplate:"""return self.body.replace(self.placeholder_text, expression)+ def _texcode_for_environment(self, environment):+ """Processes the tex_environment string to return the correct ``\\begin{environment}[extra]{extra}`` and+ ``\\end{environment}`` strings++ Parameters+ ----------+ environment : :class:`str`+ The tex_environment as a string. Acceptable formats include:+ ``{align*}``, ``align*``, ``{tabular}[t]{cccl}``, ``tabular}{cccl``, ``\\begin{tabular}[t]{cccl}``.++ Returns+ -------+ Tuple[:class:`str`, :class:`str`]+ A pair of strings representing the opening and closing of the tex environment, e.g.+ ``\\begin{tabular}{cccl}`` and ``\\end{tabular}``+ """++ # If the environment starts with \begin, remove it+ if environment[0:6] == r"\begin":+ environment = environment[6:]++ # If environment begins with { strip it+ if environment[0] == r"{":+ environment = environment[1:]++ # The \begin command takes everything and closes with a brace+ begin = r"\begin{" + environment+ if (+ begin[-1] != r"}" and begin[-1] != r"]"+ ): # If it doesn't end on } or ], assume missing }+ begin += r"}"++ # While the \end command terminates at the first closing brace+ split_at_brace = re.split(r"}", environment, 1)+ end = r"\end{" + split_at_brace[0] + r"}"++ return begin, end+def get_texcode_for_expression_in_env(self, expression, environment):"""Inserts expression into TeX template wrapped in \begin{environemnt} and \end{environment}@@ -184,8 +224,7 @@ class TexTemplate::class:`str`LaTeX code based on template, containing the given expression inside its environment, ready for typesetting"""- begin = r"\begin{" + environment + "}"- end = r"\end{" + environment + "}"+ begin, end = self._texcode_for_environment(environment)return self.body.replace(self.placeholder_text, "{0}\n{1}\n{2}".format(begin, expression, end))@@ -236,7 +275,7 @@ class TexTemplateFromFile(TexTemplate):with open(self.template_file, "r") as infile:self.body = infile.read()- def file_not_mutable():+ def file_not_mutable(self):raise Exception("Cannot modify TexTemplate when using a template file.")def add_to_preamble(self, txt, prepend=False):