Better Diagnostic for LaTeX errors

This commit is contained in:
sebastien committed 2026-09-21 09:16:13 +02:00
1 parent 0a453403cf
commit 32764c101b
2 files changed
+27 -8

No files matched your search

+9 -7
View File
@@ -177,21 +177,23 @@ def compile_to_pdf(text, output_pdf_path):
text=True,
check=False)
generated_pdf = os.path.join(temp_dir, pdf_filename)
pdf_generated = os.path.exists(generated_pdf)
if pdf_generated:
shutil.move(generated_pdf, output_pdf_path)
if result.returncode != 0:
error_lines = [
line.strip() for line in result.stdout.splitlines()
if line.lstrip().startswith("!")
]
detail = f": {error_lines[0]}" if error_lines else ""
pdf_status = "a PDF was generated" if pdf_generated else "no PDF was generated"
print(
f"Warning: LaTeX compilation failed for {output_pdf_path} "
f"(exit code {result.returncode}){detail}"
f"Warning: LaTeX compilation reported errors for {output_pdf_path} "
f"(exit code {result.returncode}; {pdf_status}){detail}"
)
generated_pdf = os.path.join(temp_dir, pdf_filename)
if os.path.exists(generated_pdf):
shutil.move(generated_pdf, output_pdf_path)
else:
elif not pdf_generated:
print(f"Warning: LaTeX compilation produced no PDF for {output_pdf_path}")
except Exception as e:
print(f"Compilation error for {output_pdf_path}: {e}")