Push Bot commited on
Commit
68083c0
·
1 Parent(s): 63cc492

Compile: use latexmk (-xelatex -f) first; accept PDF even if return code non-zero

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -429,18 +429,18 @@ def _compile_poster_pdf(OUTPUT_DIR: Path, logs):
429
  def _has(bin_name):
430
  return _sh.which(bin_name) is not None
431
 
432
- # Prefer XeLaTeX (Overleaf-like), then LuaLaTeX, then latexmk (forced XeLaTeX)
433
- if _has("xelatex"):
 
 
 
434
  cmd = ["xelatex", "-interaction=nonstopmode", "-file-line-error", tex_path.name]
435
  logs.append("▶ Compiling with xelatex …")
436
  elif _has("lualatex"):
437
  cmd = ["lualatex", "-interaction=nonstopmode", "-file-line-error", tex_path.name]
438
  logs.append("▶ Compiling with lualatex …")
439
- elif _has("latexmk"):
440
- cmd = ["latexmk", "-xelatex", "-pdf", "-interaction=nonstopmode", tex_path.name]
441
- logs.append("▶ Compiling with latexmk (-xelatex) …")
442
  else:
443
- logs.append("⚠️ No TeX engine found (xelatex/lualatex/latexmk). Skipping PDF compile.")
444
  return None
445
 
446
  import os as _os
@@ -455,17 +455,21 @@ def _compile_poster_pdf(OUTPUT_DIR: Path, logs):
455
  proc = _sp.run(cmd, cwd=str(proj_dir), stdout=_sp.PIPE, stderr=_sp.STDOUT, text=True, env=_env)
456
  if proc.stdout:
457
  logs.append(proc.stdout[-4000:])
458
- if proc.returncode != 0:
459
- logs.append(f"❌ PDF compile failed with code {proc.returncode}.")
460
- return None
461
 
462
- # Find produced PDF
463
  for out_name in ("poster_output.pdf", "poster.pdf", tex_path.stem + ".pdf"):
464
  out_path = proj_dir / out_name
465
  if out_path.exists():
466
- logs.append(f"✅ PDF generated → {out_path.relative_to(OUTPUT_DIR)}")
 
 
 
467
  return out_path
468
 
 
 
 
 
469
  logs.append("⚠️ PDF not found after compile.")
470
  return None
471
  except Exception as e:
@@ -516,10 +520,14 @@ def _compile_tex_to_pdf(tex_path: Path, logs):
516
  proc = _sp.run(cmd, cwd=str(proj_dir), stdout=_sp.PIPE, stderr=_sp.STDOUT, text=True, env=_env)
517
  if proc.stdout:
518
  logs.append(proc.stdout[-4000:])
 
519
  if proc.returncode != 0:
520
- logs.append(f"❌ PDF compile failed with code {proc.returncode}.")
 
 
 
 
521
  return None
522
- guess = proj_dir / (tex_path.stem + ".pdf")
523
  return guess if guess.exists() else None
524
  except Exception as e:
525
  logs.append(f"⚠️ PDF compile error: {e}")
 
429
  def _has(bin_name):
430
  return _sh.which(bin_name) is not None
431
 
432
+ # Most-tolerant: prefer latexmk with XeLaTeX and force (-f), then XeLaTeX, then LuaLaTeX
433
+ if _has("latexmk"):
434
+ cmd = ["latexmk", "-xelatex", "-pdf", "-f", "-interaction=nonstopmode", "-file-line-error", tex_path.name]
435
+ logs.append("▶ Compiling with latexmk (-xelatex, -f) …")
436
+ elif _has("xelatex"):
437
  cmd = ["xelatex", "-interaction=nonstopmode", "-file-line-error", tex_path.name]
438
  logs.append("▶ Compiling with xelatex …")
439
  elif _has("lualatex"):
440
  cmd = ["lualatex", "-interaction=nonstopmode", "-file-line-error", tex_path.name]
441
  logs.append("▶ Compiling with lualatex …")
 
 
 
442
  else:
443
+ logs.append("⚠️ No TeX engine found (latexmk/xelatex/lualatex). Skipping PDF compile.")
444
  return None
445
 
446
  import os as _os
 
455
  proc = _sp.run(cmd, cwd=str(proj_dir), stdout=_sp.PIPE, stderr=_sp.STDOUT, text=True, env=_env)
456
  if proc.stdout:
457
  logs.append(proc.stdout[-4000:])
 
 
 
458
 
459
+ # Accept PDF even if return code is non-zero (be tolerant)
460
  for out_name in ("poster_output.pdf", "poster.pdf", tex_path.stem + ".pdf"):
461
  out_path = proj_dir / out_name
462
  if out_path.exists():
463
+ if proc.returncode != 0:
464
+ logs.append(f"⚠️ Compile returned code {proc.returncode}, but PDF exists; using it.")
465
+ else:
466
+ logs.append(f"✅ PDF generated → {out_path.relative_to(OUTPUT_DIR)}")
467
  return out_path
468
 
469
+ if proc.returncode != 0:
470
+ logs.append(f"❌ PDF compile failed with code {proc.returncode} and no PDF produced.")
471
+ return None
472
+
473
  logs.append("⚠️ PDF not found after compile.")
474
  return None
475
  except Exception as e:
 
520
  proc = _sp.run(cmd, cwd=str(proj_dir), stdout=_sp.PIPE, stderr=_sp.STDOUT, text=True, env=_env)
521
  if proc.stdout:
522
  logs.append(proc.stdout[-4000:])
523
+ guess = proj_dir / (tex_path.stem + ".pdf")
524
  if proc.returncode != 0:
525
+ # Be tolerant: if a PDF was produced despite errors, use it.
526
+ if guess.exists():
527
+ logs.append(f"⚠️ Compile returned code {proc.returncode}, but PDF exists; using it.")
528
+ return guess
529
+ logs.append(f"❌ PDF compile failed with code {proc.returncode} and no PDF produced.")
530
  return None
 
531
  return guess if guess.exists() else None
532
  except Exception as e:
533
  logs.append(f"⚠️ PDF compile error: {e}")