summaryrefslogtreecommitdiff
path: root/run_latex.py
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthewsot@outlook.com>2020-04-13 08:40:01 -0700
committerMatthew Sotoudeh <matthewsot@outlook.com>2020-04-13 08:40:01 -0700
commit96e12c8a274ea3e08648116f3fb052e3de005560 (patch)
treecc419696e4e062fc7173876073598c98cae0aa63 /run_latex.py
parent229b0f318e0160013c9c5700a22cc13da37fdcd8 (diff)
Initial code release
Diffstat (limited to 'run_latex.py')
-rw-r--r--run_latex.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/run_latex.py b/run_latex.py
new file mode 100644
index 0000000..2d7d618
--- /dev/null
+++ b/run_latex.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+import glob
+import os
+import shutil
+import subprocess
+import sys
+
+texlive, latexrun, job_name, main_file, output_file = sys.argv[1:6]
+sources = sys.argv[6:]
+
+env = dict(os.environ)
+# Generated files (eg. outputs of pdfcrop) are placed under bazel-out/*/bin.
+# This references the bin directory so pdflatex can find them. There is
+# probably a better way of doing this.
+bin_dirs = set()
+for source in sources:
+ if source.startswith("bazel-out"):
+ bin_dirs.add("%s/%s" % (os.getcwd(), "/".join(source.split("/")[:3])))
+env["TEXINPUTS"] = ".:%s:" % ":".join(sorted(bin_dirs))
+
+env["PATH"] = "%s:%s" % (os.path.abspath("%s/bin/x86_64" % texlive), env["PATH"])
+env["PATH"] = "%s:%s" % (os.path.abspath(texlive), env["PATH"])
+env["TEXMFHOME"] = os.path.abspath(texlive)
+env["TEXMFVAR"] = os.path.abspath(texlive)
+env["SOURCE_DATE_EPOCH"] = "0"
+
+return_code = subprocess.call(
+ args=[
+ "python3",
+ latexrun,
+ "--latex-args=-jobname=" + job_name,
+ "--latex-cmd=pdflatex",
+ "--bibtex-cmd=bibtex",
+ "-Wall",
+ main_file,
+ ],
+ env=env,
+)
+
+if return_code != 0:
+ sys.exit(return_code)
+os.rename(job_name + ".pdf", output_file)
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback