Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to remove non-svg LaTeX files #3322

Merged
merged 39 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c635535
Added ability to remove latex junk (default True)
JasonGrace2282 Aug 9, 2023
c801683
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
c4e529e
Merge branch 'main' into latex_junk_remover
JasonGrace2282 Aug 9, 2023
7f1c735
Fixed tests (hopefully), and whitelisted .tex
JasonGrace2282 Aug 9, 2023
f9a0281
Merge branch 'latex_junk_remover' of https://github.com/JasonGrace228…
JasonGrace2282 Aug 9, 2023
e2b8489
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
e29473b
reverted weird changes from merge
JasonGrace2282 Aug 9, 2023
b23c30d
See previous commit message
JasonGrace2282 Aug 9, 2023
5c39ce1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
5750360
Fixed logs-too-long test
JasonGrace2282 Aug 9, 2023
227c269
Fixed log output
JasonGrace2282 Aug 9, 2023
7958f5f
Fixed typo ;)
JasonGrace2282 Aug 9, 2023
e4b2e01
deleted unused variable
JasonGrace2282 Aug 9, 2023
7d1cccb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2023
03560b8
moved latex deletion to tex_file_writing.py
JasonGrace2282 Aug 11, 2023
7f044cb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
f888c51
removed changes in scene files
JasonGrace2282 Aug 11, 2023
1f48107
Merge branch 'latex_junk_remover' of https://github.com/JasonGrace228…
JasonGrace2282 Aug 11, 2023
133ae4d
Added caching based on LaTeX expression .svg
JasonGrace2282 Aug 11, 2023
5a14356
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
009d551
Deleted unused function in delete_old_tex
JasonGrace2282 Aug 11, 2023
bf9f12c
make if condition more readable
JasonGrace2282 Aug 11, 2023
d6bab49
cleaned up svg file check
JasonGrace2282 Aug 11, 2023
d7aa545
Merge branch 'latex_junk_remover' of https://github.com/JasonGrace228…
JasonGrace2282 Aug 11, 2023
9a0240e
changed blacklist -> whitelist for file endings
JasonGrace2282 Aug 12, 2023
205b804
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 12, 2023
e323c08
Reverted docstring change
JasonGrace2282 Aug 12, 2023
486ba62
Merge branch 'latex_junk_remover' of https://github.com/JasonGrace228…
JasonGrace2282 Aug 12, 2023
6be5927
Updated delete_non_svg files docstring
JasonGrace2282 Aug 12, 2023
40257f7
Changed list to a set
JasonGrace2282 Aug 12, 2023
7860e4a
Merge branch 'main' into latex_junk_remover
JasonGrace2282 Sep 1, 2023
b91e5b8
Merge branch 'main' into latex_junk_remover
JasonGrace2282 Sep 4, 2023
7bc4442
Merge branch 'ManimCommunity:main' into latex_junk_remover
JasonGrace2282 Sep 23, 2023
e29c6d5
Merge branch 'main' into latex_junk_remover
JasonGrace2282 Oct 29, 2023
613bea2
Update manim/_config/utils.py
MrDiver Nov 4, 2023
fd81de7
Update manim/cli/render/global_options.py
MrDiver Nov 4, 2023
a0d71bf
Merge branch 'main' into latex_junk_remover
MrDiver Nov 4, 2023
a91cf07
added one test for the no_latex_cleanup config option
behackl Nov 4, 2023
572e68a
Merge branch 'main' into latex_junk_remover
behackl Nov 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class MyScene(Scene):
"write_to_movie",
"zero_pad",
"force_window",
"no_latex_cleanup",
}

def __init__(self) -> None:
Expand Down Expand Up @@ -580,6 +581,7 @@ def digest_parser(self, parser: configparser.ConfigParser) -> ManimConfig:
"use_projection_stroke_shaders",
"enable_wireframe",
"force_window",
"no_latex_cleanup",
]:
setattr(self, key, parser["CLI"].getboolean(key, fallback=False))

Expand Down Expand Up @@ -756,6 +758,7 @@ def digest_args(self, args: argparse.Namespace) -> ManimConfig:
"enable_wireframe",
"force_window",
"dry_run",
"no_latex_cleanup",
]:
if hasattr(args, key):
attr = getattr(args, key)
Expand Down Expand Up @@ -960,6 +963,12 @@ def digest_file(self, filename: str | os.PathLike) -> ManimConfig:
doc="Set to force window when using the opengl renderer",
)

no_latex_cleanup = property(
lambda self: self._d["no_latex_cleanup"],
lambda self, val: self._set_boolean("no_latex_cleanup", val),
doc="Deletes .aux, .dvi, and .log files produced by Tex and MathTex.",
MrDiver marked this conversation as resolved.
Show resolved Hide resolved
)

@property
def verbosity(self):
"""Logger verbosity; "DEBUG", "INFO", "WARNING", "ERROR", or "CRITICAL" (-v)."""
Expand Down
6 changes: 6 additions & 0 deletions manim/cli/render/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ def validate_gui_location(ctx, param, value):
help="Renders animations without outputting image or video files and disables the window",
default=False,
),
option(
"--no_latex_cleanup",
is_flag=True,
help="Deletes .aux, .dvi, and .log files produced by Tex and MathTex.",
MrDiver marked this conversation as resolved.
Show resolved Hide resolved
default=False,
),
)
6 changes: 6 additions & 0 deletions manim/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def __deepcopy__(self, clone_from_id):
result.mobject_updater_lists.append((mobject_clone, cloned_updaters))
return result

def delete_old_latex(self) -> int:
return self.renderer.file_writer.delete_tex_files(self.__class__.__name__)

def render(self, preview: bool = False):
"""
Renders this Scene.
Expand All @@ -232,12 +235,15 @@ def render(self, preview: bool = False):
# We have to reset these settings in case of multiple renders.
self.renderer.scene_finished(self)

deleted_latex = self.delete_old_latex() if not config["no_latex_cleanup"] else 0
Fixed Show fixed Hide fixed
# Show info only if animations are rendered or to get image
if (
self.renderer.num_plays
or config["format"] == "png"
or config["save_last_frame"]
):
# Maybe add this logging output to tests?
# logger.info(f"{deleted_latex} non-essential LaTeX files deleted.{' To keep these LaTeX files, try passing in `--no_latex_cleanup`' if deleted_latex else ''}")
logger.info(
f"Rendered {str(self)}\nPlayed {self.renderer.num_plays} animations",
)
Expand Down
44 changes: 43 additions & 1 deletion manim/scene/scene_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, renderer, scene_name, **kwargs):
"or set path to the ffmpeg executable under the ffmpeg header in Manim's configuration."
)

def init_output_directories(self, scene_name):
def init_output_directories(self, scene_name: str):
"""Initialise output directories.

Notes
Expand Down Expand Up @@ -172,6 +172,48 @@ def init_output_directories(self, scene_name):
scene_name=scene_name, module_name=module_name, log_dir=log_dir
)

def delete_tex_files(
self, scene_name: str, additional_endings: tuple[str] = ()
) -> int:
"""Deletes the .dvi, .aux, and .log files produced when using `Tex` or `MathTex`

Parameters:
-----------
scene_name
Name of class inheriting from `Scene`
additional_endings
Additional Endings to remove in Tex folder

Returns:
--------
:class:`int`
How many files were deleted
"""
# ideally placed in self.init_output_directories, but when running tests that method isn't called?
# resulting in an AttributeError. Instead, just get directory here.
try:
tex_files_directory = guarantee_existence(
config.get_dir(
"tex_dir",
module_name=config.get_dir("input_file").stem
if config["input_file"]
else "",
scene_name=scene_name,
)
)

file_endings = (".dvi", ".aux", ".log", *additional_endings)
files_deleted = 0
for file_name in tex_files_directory.iterdir():
file = tex_files_directory / file_name
if any(file.suffix == s for s in file_endings):
file.unlink()
files_deleted += 1
return files_deleted
except Exception as e:
logger.info("An error occured while trying to clean up LaTeX files")
return 0

def finish_last_section(self) -> None:
"""Delete current section if it is empty."""
if len(self.sections) and self.sections[-1].is_empty():
Expand Down