Created
November 13, 2013 02:31
-
-
Save wkerzendorf/7442635 to your computer and use it in GitHub Desktop.
pdflatex python script with latex/bibtex/latex/latex and moving unwanted files into output-directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import os | |
import shutil | |
pdflatex_bin = 'pdflatex' | |
bibtex_bin = 'bibtex' | |
move_extensions = ('.log', '.aux', '.bbl', '.blg') | |
# checking for output directory | |
output_directory = None | |
args = [] | |
for arg in sys.argv: | |
if 'output-directory' in arg: | |
output_directory = arg.split('=')[-1].strip() | |
continue | |
args.append(arg) | |
pdflatex_cmd = "{0:s} {1:s}".format(pdflatex_bin, ' '.join(args[1:])) | |
bibtex_cmd = "{0:s} {1:s}".format(bibtex_bin, args[-1].replace('.tex', '')) | |
print pdflatex_cmd | |
print bibtex_cmd | |
if output_directory and not os.path.exists(output_directory): | |
os.mkdir(output_directory) | |
os.system(pdflatex_cmd) | |
os.system(bibtex_cmd) | |
os.system(pdflatex_cmd) | |
os.system(pdflatex_cmd) | |
if output_directory: | |
for ext in move_extensions: | |
fname = args[-1].replace('.tex', ext) | |
try: | |
shutil.move(fname, os.path.join(output_directory, fname)) | |
except IOError: | |
print "** Failed to move {0:s}".format(fname) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment