Skip to content

Instantly share code, notes, and snippets.

@nickrsan
Created October 8, 2019 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickrsan/af0248f146d64a45b0e2afa451904f55 to your computer and use it in GitHub Desktop.
Save nickrsan/af0248f146d64a45b0e2afa451904f55 to your computer and use it in GitHub Desktop.
# Calls the full pipeline needed to get a PDF with BibTex working
# pdfLaTeX->BibTeX->pdfLaTeX->pdfLaTeX
#
# Designed for use as a called script from TeXworks in the TeXLive distribution, but
# easily adapted for other workflows
# Make sure to set texlive_folder below!
# Adapted from https://tex.stackexchange.com/a/308727
import os
import sys
import subprocess
texlive_folder = r"" # path to folder - should likely end with something like "\texlive\2019\tlpkg\"
path_items = [os.path.join(texlive_folder, "tlperl", "bin"),
os.path.join(texlive_folder, "tlgs", "bin"),
os.path.join(texlive_folder, "tlpkg", "texworks")
]
# add the TeX components to the path
os.environ["PATH"] += os.pathsep + os.pathsep.join(path_items)
# set up the commands we'll want to run, in order - the arguments come from what
# TeXworks wants to pass to the commands by default if we ran this all manually
# arg order
# 1 basename
# 2 fullname
# 3 synctexoption
commands = [
['pdflatex.exe', sys.argv[3], sys.argv[2]],
['bibtex.exe', sys.argv[1] + '.aux'],
['pdflatex.exe', sys.argv[3], sys.argv[2]],
['pdflatex.exe', sys.argv[3], sys.argv[2]],
]
return_code = 0 # start with a normal return code
for c in commands:
try:
subprocess.check_output(c)
except subprocess.CalledProcessError as exc:
print "error code", exc.returncode, exc.output
return_code = exc.returncode # if we get any kind of exception, set it as our return code
# but still try to run the rest
sys.exit(return_code) # return the last error code we got so that if there was an error we let TeXworks know
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment