Spaces:
Running
Running
Push Bot
commited on
Commit
·
79ebf1d
1
Parent(s):
abc742b
Ultra-lenient compile: demote Package/TikZ errors via pretex injection; latexmk -f with -pretex; fallbacks inject pretex too
Browse files
app.py
CHANGED
|
@@ -72,57 +72,7 @@ def _write_logs(log_path: Path, logs):
|
|
| 72 |
except Exception:
|
| 73 |
pass
|
| 74 |
|
| 75 |
-
|
| 76 |
-
"""Best-effort, non-invasive fixes to let compilation proceed.
|
| 77 |
-
- Ensure TikZ \node lines have trailing ';' and an empty label '{}' if missing.
|
| 78 |
-
- Replace Unicode bullets with \textbullet{}.
|
| 79 |
-
Operates in-place on the run-local copy only.
|
| 80 |
-
"""
|
| 81 |
-
try:
|
| 82 |
-
text = tex_path.read_text(encoding="utf-8")
|
| 83 |
-
lines = text.splitlines()
|
| 84 |
-
changed = False
|
| 85 |
-
cnt_semicolon = 0
|
| 86 |
-
cnt_emptylabel = 0
|
| 87 |
-
cnt_bullet = 0
|
| 88 |
-
new_lines = []
|
| 89 |
-
for line in lines:
|
| 90 |
-
orig = line
|
| 91 |
-
# Replace bullets
|
| 92 |
-
if "\\•" in line or "•" in line:
|
| 93 |
-
line = line.replace("\\•", r"\\textbullet{}")
|
| 94 |
-
line = line.replace("•", r"\\textbullet{}")
|
| 95 |
-
if line != orig:
|
| 96 |
-
cnt_bullet += 1
|
| 97 |
-
orig = line
|
| 98 |
-
# Fix TikZ node syntax (line-based heuristic)
|
| 99 |
-
if "\\node" in line:
|
| 100 |
-
# Ensure semicolon at end of command line
|
| 101 |
-
stripped = line.rstrip()
|
| 102 |
-
if not stripped.endswith(";"):
|
| 103 |
-
line = stripped + ";"
|
| 104 |
-
cnt_semicolon += 1
|
| 105 |
-
# Add empty label '{}' before the first trailing ';' if no braces after ')'
|
| 106 |
-
try:
|
| 107 |
-
close_paren = line.rfind(")")
|
| 108 |
-
if close_paren != -1:
|
| 109 |
-
tail = line[close_paren+1:]
|
| 110 |
-
semi = tail.find(";")
|
| 111 |
-
if semi != -1:
|
| 112 |
-
between = tail[:semi]
|
| 113 |
-
if "{" not in between:
|
| 114 |
-
line = line[:close_paren+1] + " {}" + tail
|
| 115 |
-
cnt_emptylabel += 1
|
| 116 |
-
except Exception:
|
| 117 |
-
pass
|
| 118 |
-
new_lines.append(line)
|
| 119 |
-
if new_lines != lines:
|
| 120 |
-
tex_path.write_text("\n".join(new_lines), encoding="utf-8")
|
| 121 |
-
logs.append(
|
| 122 |
-
f"🧯 Lenient sanitizer: +semicolon={cnt_semicolon}, +emptylabel={cnt_emptylabel}, bullets_fixed={cnt_bullet}"
|
| 123 |
-
)
|
| 124 |
-
except Exception as e:
|
| 125 |
-
logs.append(f"⚠️ sanitizer skipped: {e}")
|
| 126 |
|
| 127 |
def _on_rm_error(func, path, exc_info):
|
| 128 |
# fix "PermissionError: [Errno 13] Permission denied" for readonly files
|
|
@@ -481,19 +431,25 @@ def _compile_poster_pdf(OUTPUT_DIR: Path, logs):
|
|
| 481 |
def _has(bin_name):
|
| 482 |
return _sh.which(bin_name) is not None
|
| 483 |
|
| 484 |
-
# Apply lenient sanitizer on the main tex before compile
|
| 485 |
-
_sanitize_tex_lenient(tex_path, logs)
|
| 486 |
-
|
| 487 |
# Most-tolerant: prefer latexmk with XeLaTeX and force (-f), then XeLaTeX, then LuaLaTeX
|
|
|
|
| 488 |
if _has("latexmk"):
|
| 489 |
-
cmd = [
|
| 490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
elif _has("xelatex"):
|
| 492 |
-
|
| 493 |
-
|
|
|
|
|
|
|
| 494 |
elif _has("lualatex"):
|
| 495 |
-
|
| 496 |
-
|
|
|
|
| 497 |
else:
|
| 498 |
logs.append("⚠️ No TeX engine found (latexmk/xelatex/lualatex). Skipping PDF compile.")
|
| 499 |
return None
|
|
@@ -551,19 +507,24 @@ def _compile_tex_to_pdf(tex_path: Path, logs):
|
|
| 551 |
import shutil as _sh, subprocess as _sp
|
| 552 |
def _has(bin_name):
|
| 553 |
return _sh.which(bin_name) is not None
|
| 554 |
-
#
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
elif _has("lualatex"):
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
cmd = ["latexmk", "-xelatex", "-pdf", "-interaction=nonstopmode", tex_path.name]
|
| 566 |
-
logs.append("▶ Compiling with latexmk (-xelatex) …")
|
| 567 |
else:
|
| 568 |
logs.append("⚠️ No TeX engine found (xelatex/lualatex/latexmk).")
|
| 569 |
return None
|
|
|
|
| 72 |
except Exception:
|
| 73 |
pass
|
| 74 |
|
| 75 |
+
## Removed sanitizer per request: do not mutate user-generated TeX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
def _on_rm_error(func, path, exc_info):
|
| 78 |
# fix "PermissionError: [Errno 13] Permission denied" for readonly files
|
|
|
|
| 431 |
def _has(bin_name):
|
| 432 |
return _sh.which(bin_name) is not None
|
| 433 |
|
|
|
|
|
|
|
|
|
|
| 434 |
# Most-tolerant: prefer latexmk with XeLaTeX and force (-f), then XeLaTeX, then LuaLaTeX
|
| 435 |
+
pretex = r"\nonstopmode\scrollmode\makeatletter\let\pgf@error\pgf@warning\let\GenericError\GenericWarning\let\PackageError\PackageWarning\makeatother"
|
| 436 |
if _has("latexmk"):
|
| 437 |
+
cmd = [
|
| 438 |
+
"latexmk", "-xelatex", "-pdf", "-f",
|
| 439 |
+
"-interaction=nonstopmode", "-file-line-error",
|
| 440 |
+
f"-pretex={pretex}",
|
| 441 |
+
tex_path.name,
|
| 442 |
+
]
|
| 443 |
+
logs.append("▶ Compiling with latexmk (-xelatex, -f, pretex demote errors) …")
|
| 444 |
elif _has("xelatex"):
|
| 445 |
+
# Inject pretex macros via direct input to engine (no file mutation)
|
| 446 |
+
injected = pretex + f"\\input{{{tex_path.name}}}"
|
| 447 |
+
cmd = ["xelatex", "-interaction=nonstopmode", "-file-line-error", injected]
|
| 448 |
+
logs.append("▶ Compiling with xelatex (pretex injected) …")
|
| 449 |
elif _has("lualatex"):
|
| 450 |
+
injected = pretex + f"\\input{{{tex_path.name}}}"
|
| 451 |
+
cmd = ["lualatex", "-interaction=nonstopmode", "-file-line-error", injected]
|
| 452 |
+
logs.append("▶ Compiling with lualatex (pretex injected) …")
|
| 453 |
else:
|
| 454 |
logs.append("⚠️ No TeX engine found (latexmk/xelatex/lualatex). Skipping PDF compile.")
|
| 455 |
return None
|
|
|
|
| 507 |
import shutil as _sh, subprocess as _sp
|
| 508 |
def _has(bin_name):
|
| 509 |
return _sh.which(bin_name) is not None
|
| 510 |
+
# Most-tolerant: latexmk first with pretex demoting errors; fallbacks inject pretex, too
|
| 511 |
+
pretex = r"\nonstopmode\scrollmode\makeatletter\let\pgf@error\pgf@warning\let\GenericError\GenericWarning\let\PackageError\PackageWarning\makeatother"
|
| 512 |
+
if _has("latexmk"):
|
| 513 |
+
cmd = [
|
| 514 |
+
"latexmk", "-xelatex", "-pdf", "-f",
|
| 515 |
+
"-interaction=nonstopmode", "-file-line-error",
|
| 516 |
+
f"-pretex={pretex}",
|
| 517 |
+
tex_path.name,
|
| 518 |
+
]
|
| 519 |
+
logs.append("▶ Compiling with latexmk (-xelatex, -f, pretex demote errors) …")
|
| 520 |
+
elif _has("xelatex"):
|
| 521 |
+
injected = pretex + f"\\input{{{tex_path.name}}}"
|
| 522 |
+
cmd = ["xelatex", "-interaction=nonstopmode", "-file-line-error", injected]
|
| 523 |
+
logs.append("▶ Compiling with xelatex (pretex injected) …")
|
| 524 |
elif _has("lualatex"):
|
| 525 |
+
injected = pretex + f"\\input{{{tex_path.name}}}"
|
| 526 |
+
cmd = ["lualatex", "-interaction=nonstopmode", "-file-line-error", injected]
|
| 527 |
+
logs.append("▶ Compiling with lualatex (pretex injected) …")
|
|
|
|
|
|
|
| 528 |
else:
|
| 529 |
logs.append("⚠️ No TeX engine found (xelatex/lualatex/latexmk).")
|
| 530 |
return None
|