From e0e7e24351f433e981464194fb66cacbfed449e0 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Mon, 19 Dec 2022 17:01:06 -0800 Subject: [PATCH] Move display_during_execturion call Such that it only gets called when a new svg needs to be written --- manimlib/mobject/svg/mtex_mobject.py | 8 +++----- manimlib/mobject/svg/tex_mobject.py | 8 +++----- manimlib/utils/tex_file_writing.py | 6 ++++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/manimlib/mobject/svg/mtex_mobject.py b/manimlib/mobject/svg/mtex_mobject.py index fdf33663..fdb40cd3 100644 --- a/manimlib/mobject/svg/mtex_mobject.py +++ b/manimlib/mobject/svg/mtex_mobject.py @@ -3,7 +3,6 @@ from __future__ import annotations import re from manimlib.mobject.svg.string_mobject import StringMobject -from manimlib.utils.tex_file_writing import display_during_execution from manimlib.utils.tex_file_writing import tex_content_to_svg_file from typing import TYPE_CHECKING @@ -79,10 +78,9 @@ class MTex(StringMobject): ) def get_file_path_by_content(self, content: str) -> str: - with display_during_execution(f"Writing \"{self.tex_string}\""): - file_path = tex_content_to_svg_file( - content, self.template, self.additional_preamble - ) + file_path = tex_content_to_svg_file( + content, self.template, self.additional_preamble, self.tex_string + ) return file_path # Parsing diff --git a/manimlib/mobject/svg/tex_mobject.py b/manimlib/mobject/svg/tex_mobject.py index 549ccfe9..2b5b38bc 100644 --- a/manimlib/mobject/svg/tex_mobject.py +++ b/manimlib/mobject/svg/tex_mobject.py @@ -11,7 +11,6 @@ from manimlib.constants import MED_LARGE_BUFF, SMALL_BUFF from manimlib.mobject.geometry import Line from manimlib.mobject.svg.svg_mobject import SVGMobject from manimlib.mobject.types.vectorized_mobject import VGroup -from manimlib.utils.tex_file_writing import display_during_execution from manimlib.utils.tex_file_writing import tex_content_to_svg_file from typing import TYPE_CHECKING @@ -86,10 +85,9 @@ class SingleStringTex(SVGMobject): def get_file_path(self) -> str: content = self.get_tex_file_body(self.tex_string) - with display_during_execution(f"Writing \"{self.tex_string}\""): - file_path = tex_content_to_svg_file( - content, self.template, self.additional_preamble - ) + file_path = tex_content_to_svg_file( + content, self.template, self.additional_preamble, self.tex_string + ) return file_path def get_tex_file_body(self, tex_string: str) -> str: diff --git a/manimlib/utils/tex_file_writing.py b/manimlib/utils/tex_file_writing.py index 14ce8403..6538adc9 100644 --- a/manimlib/utils/tex_file_writing.py +++ b/manimlib/utils/tex_file_writing.py @@ -52,7 +52,8 @@ def get_tex_config() -> dict[str, str]: def tex_content_to_svg_file( - content: str, template: str, additional_preamble: str + content: str, template: str, additional_preamble: str, + short_tex: str ) -> str: tex_config = get_tex_config() if not template or template == tex_config["template"]: @@ -78,7 +79,8 @@ def tex_content_to_svg_file( ) if not os.path.exists(svg_file): # If svg doesn't exist, create it - create_tex_svg(full_tex, svg_file, compiler) + with display_during_execution("Writing " + short_tex): + create_tex_svg(full_tex, svg_file, compiler) return svg_file