A community-maintained Python framework for creating mathematical animations.
Enhancement: parse .log file and try to print LaTeX errors if compilation fails (#1030)
Benjamin Hackl2bfc66198e76
diff --git a/manim/utils/tex_file_writing.py b/manim/utils/tex_file_writing.pyindex 3ca111248..43bba884a 100644--- a/manim/utils/tex_file_writing.py+++ b/manim/utils/tex_file_writing.py@@ -164,6 +164,30 @@ def compile_tex(tex_file, tex_compiler, output_format):exit_code = os.system(command)if exit_code != 0:log_file = tex_file.replace(".tex", ".log")+ if not Path(log_file).exists():+ raise RuntimeError(+ f"{tex_compiler} failed but did not produce a log file. "+ "Check your LaTeX installation."+ )+ with open(log_file, "r") as f:+ log = f.readlines()+ log_error_pos = [+ ind for (ind, line) in enumerate(log) if line.startswith("!")+ ]+ if log_error_pos:+ logger.error(f"LaTeX compilation error! {tex_compiler} reports:")+ for lineno in log_error_pos:+ # search for a line starting with "l." in the next+ # few lines past the error; otherwise just print some lines.+ printed_lines = 1+ for _ in range(10):+ if log[lineno + printed_lines].startswith("l."):+ break+ printed_lines += 1++ for line in log[lineno : lineno + printed_lines + 1]:+ logger.error(line)+raise ValueError(f"{tex_compiler} error converting to"f" {output_format[1:]}. See log output above or"