Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed bug with propagation of ``tex_template`` value when using ``tempconfig`` (#2888)

Benjamin Hackl22ae67e47f9c
diff --git a/manim/_config/utils.py b/manim/_config/utils.py
index 9b85e5723..3b0dab628 100644
--- a/manim/_config/utils.py
+++ b/manim/_config/utils.py
@@ -286,6 +286,7 @@ class ManimConfig(MutableMapping):
"scene_names",
"show_in_file_browser",
"tex_dir",
+ "tex_template",
"tex_template_file",
"text_dir",
"upto_animation_number",
@@ -361,6 +362,8 @@ class ManimConfig(MutableMapping):
if isinstance(obj, ManimConfig):
self._d.update(obj._d)
+ if obj.tex_template:
+ self.tex_template = obj.tex_template
elif isinstance(obj, dict):
# First update the underlying _d, then update other properties
@@ -1540,7 +1543,7 @@ class ManimConfig(MutableMapping):
if fn:
self._tex_template = TexTemplateFromFile(filename=fn)
else:
- self._tex_template = TexTemplateLibrary.default.copy()
+ self._tex_template = TexTemplate()
return self._tex_template
@tex_template.setter
@@ -1562,10 +1565,8 @@ class ManimConfig(MutableMapping):
)
else:
self._d["tex_template_file"] = Path(val)
- self._tex_template = TexTemplateFromFile(filename=val)
else:
self._d["tex_template_file"] = val # actually set the falsy value
- self._tex_template = TexTemplate() # but don't use it
@property
def plugins(self):
diff --git a/manim/cli/render/commands.py b/manim/cli/render/commands.py
index 97ba883ff..f10567659 100644
--- a/manim/cli/render/commands.py
+++ b/manim/cli/render/commands.py
@@ -98,7 +98,7 @@ def render(
keep_running = True
while keep_running:
for SceneClass in scene_classes_from_file(file):
- with tempconfig(config):
+ with tempconfig({}):
scene = SceneClass(renderer)
rerun = scene.render()
if rerun or config["write_all"]:
@@ -116,7 +116,7 @@ def render(
else:
for SceneClass in scene_classes_from_file(file):
try:
- with tempconfig(config):
+ with tempconfig({}):
scene = SceneClass()
scene.render()
except Exception:
diff --git a/manim/utils/tex.py b/manim/utils/tex.py
index 2ace7f230..a30533123 100644
--- a/manim/utils/tex.py
+++ b/manim/utils/tex.py
@@ -96,6 +96,14 @@ class TexTemplate:
)
self._rebuild()
+ def __eq__(self, other: TexTemplate) -> bool:
+ return (
+ self.body == other.body
+ and self.tex_compiler == other.tex_compiler
+ and self.output_format == other.output_format
+ and self.post_doc_commands == other.post_doc_commands
+ )
+
def _rebuild(self):
"""Rebuilds the entire TeX template text from ``\\documentclass`` to ``\\end{document}`` according to all settings and choices."""
self.body = (
diff --git a/tests/module/mobject/text/test_texmobject.py b/tests/module/mobject/text/test_texmobject.py
index 8e0420a23..4585a82fe 100644
--- a/tests/module/mobject/text/test_texmobject.py
+++ b/tests/module/mobject/text/test_texmobject.py
@@ -4,19 +4,19 @@ from pathlib import Path
import pytest
-from manim import MathTex, SingleStringMathTex, Tex, TexTemplate, config
+from manim import MathTex, SingleStringMathTex, Tex, TexTemplate, config, tempconfig
from manim.mobject.types.vectorized_mobject import VMobject
from manim.utils.color import RED
def test_MathTex():
MathTex("a^2 + b^2 = c^2")
- assert Path(config.media_dir, "Tex", "3879f6b03bc495cd.svg").exists()
+ assert Path(config.media_dir, "Tex", "eb38bdba08f46c80.svg").exists()
def test_SingleStringMathTex():
SingleStringMathTex("test")
- assert Path(config.media_dir, "Tex", "79822967f1fa1935.svg").exists()
+ assert Path(config.media_dir, "Tex", "5b2faa68ebf42d1e.svg").exists()
@pytest.mark.parametrize( # : PT006
@@ -30,12 +30,12 @@ def test_double_braces_testing(text_input, length_sub):
def test_tex():
Tex("The horse does not eat cucumber salad.")
- assert Path(config.media_dir, "Tex", "983949cac5bdd272.svg").exists()
+ assert Path(config.media_dir, "Tex", "f2e45e6e82d750e6.svg").exists()
def test_percent_char_rendering():
Tex(r"\%")
- assert Path(config.media_dir, "Tex", "ce6e53f2d9c537bb.tex").exists()
+ assert Path(config.media_dir, "Tex", "3f48edf8ebaf82c8.tex").exists()
def test_tex_whitespace_arg():
@@ -171,3 +171,13 @@ def test_error_in_nested_context(capsys):
stdout = str(capsys.readouterr().out)
# validate useless context is not included
assert r"\begin{frame}" not in stdout
+
+
+def test_tempconfig_resetting_tex_template():
+ my_template = TexTemplate()
+ my_template.preamble = "Custom preamble!"
+ tex_template_config_value = config.tex_template
+ with tempconfig({"tex_template": my_template}):
+ assert config.tex_template.preamble == "Custom preamble!"
+
+ assert config.tex_template.preamble != "Custom preamble!"
diff --git a/tests/opengl/test_texmobject_opengl.py b/tests/opengl/test_texmobject_opengl.py
index 7c2b0c5f2..392513ccb 100644
--- a/tests/opengl/test_texmobject_opengl.py
+++ b/tests/opengl/test_texmobject_opengl.py
@@ -9,12 +9,12 @@ from manim import MathTex, SingleStringMathTex, Tex, config
def test_MathTex(using_opengl_renderer):
MathTex("a^2 + b^2 = c^2")
- assert Path(config.media_dir, "Tex", "3879f6b03bc495cd.svg").exists()
+ assert Path(config.media_dir, "Tex", "eb38bdba08f46c80.svg").exists()
def test_SingleStringMathTex(using_opengl_renderer):
SingleStringMathTex("test")
- assert Path(config.media_dir, "Tex", "79822967f1fa1935.svg").exists()
+ assert Path(config.media_dir, "Tex", "5b2faa68ebf42d1e.svg").exists()
@pytest.mark.parametrize( # : PT006
@@ -28,7 +28,7 @@ def test_double_braces_testing(using_opengl_renderer, text_input, length_sub):
def test_tex(using_opengl_renderer):
Tex("The horse does not eat cucumber salad.")
- assert Path(config.media_dir, "Tex", "983949cac5bdd272.svg").exists()
+ assert Path(config.media_dir, "Tex", "f2e45e6e82d750e6.svg").exists()
def test_tex_whitespace_arg(using_opengl_renderer):