-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildScript.py
executable file
·32 lines (25 loc) · 1.17 KB
/
buildScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
from subprocess import check_call
import os
import sys
if len(sys.argv) != 3:
sys.exit('the first argument has to be the name of the .tex file. The second argument has to be the name of the output directory')
texEnding = '.tex'
fileNameNoTex = os.path.splitext(sys.argv[1])[0]
outDir = sys.argv[2]
# check if tex file exists
if not os.path.exists(fileNameNoTex + texEnding):
sys.exit(fileNameNoTex + texEnding + ' does not exist')
# create out direcotry if necessary
if os.path.exists(outDir):
if not os.path.isdir(outDir):
sys.exit(outDir + ' is a file, not a folder. Remove the file ' + outDir + ' or use a different output directory name')
else:
os.makedirs(outDir)
if not os.path.isdir(outDir): # should never happen
sys.exit('FATAL: ' + outDir + ' was not be created')
# as descriped in http://stackoverflow.com/questions/2461905/compiling-latex-bib-source
check_call(['pdflatex', '-output-directory', outDir, fileNameNoTex + texEnding])
check_call(['bibtex', outDir + '/' + fileNameNoTex + '.aux'])
check_call(['pdflatex', '-output-directory', outDir, fileNameNoTex + texEnding])
check_call(['pdflatex', '-output-directory', outDir, fileNameNoTex + texEnding])