utilities to fix LaTeX issues
This commit is contained in:
1 parent
2a4c5f4f7c
commit
a56fc6e680
7 files changed
+164
-2
No files matched your search
@@ -141,6 +141,13 @@ import subprocess
|
||||
|
||||
from .configuration import LATEX_AFTER, LATEX_BEFORE
|
||||
|
||||
LATEX_WARNING_MARKER = "[Copienator:latex-warning] "
|
||||
|
||||
|
||||
def report_latex_warning(output_pdf_path) -> None:
|
||||
"""Emit a stable, machine-readable path alongside human diagnostics."""
|
||||
print(f"{LATEX_WARNING_MARKER}{Path(output_pdf_path).resolve()}")
|
||||
|
||||
|
||||
def compile_to_pdf(text, output_pdf_path, *, strict=False):
|
||||
"""Wraps text in standalone header/footer templates and compiles it to PDF."""
|
||||
@@ -185,6 +192,7 @@ def compile_to_pdf(text, output_pdf_path, *, strict=False):
|
||||
shutil.move(generated_pdf, output_pdf_path)
|
||||
|
||||
if result.returncode != 0:
|
||||
report_latex_warning(output_pdf_path)
|
||||
lines = result.stdout.splitlines()
|
||||
first = next((i for i, line in enumerate(lines) if line.lstrip().startswith("!")), None)
|
||||
detail = "\n" + "\n".join(lines[first:first + 5]) if first is not None else ""
|
||||
@@ -196,10 +204,12 @@ def compile_to_pdf(text, output_pdf_path, *, strict=False):
|
||||
if strict:
|
||||
raise RuntimeError(f"LaTeX failed for {output_pdf_path}{detail}")
|
||||
elif not pdf_generated:
|
||||
report_latex_warning(output_pdf_path)
|
||||
print(f"Warning: LaTeX compilation produced no PDF for {output_pdf_path}")
|
||||
if strict:
|
||||
raise RuntimeError(f"No PDF generated for {output_pdf_path}")
|
||||
except Exception as e:
|
||||
if strict:
|
||||
raise
|
||||
report_latex_warning(output_pdf_path)
|
||||
print(f"Compilation error for {output_pdf_path}: {e}")
|
||||
Reference in new issue
Block a user