Skip to content

Instantly share code, notes, and snippets.

@giuliano-oliveira
Last active Aug 16, 2020
Embed
What would you like to do?
Move tex files and compiles them in a temp dir, then move pdf file to root. Works on linux and requires nodemon and latexmk
#!/usr/bin/env python3
import argparse
import os
from tempfile import mkdtemp
parser=argparse.ArgumentParser()
parser.add_argument("input",type=str)
args=parser.parse_args()
pwd=os.path.realpath(os.getcwd())
tmp_dir=mkdtemp(prefix="tex.py-")
out_pdf=os.path.splitext(os.path.split(args.input)[-1])[0] +".pdf"
##create empty pdf file
#https://stackoverflow.com/a/17280876/5133524
with open(out_pdf,"w") as f:
f.write("%PDF-1.0\n1 0 obj<</Pages 2 0 R>>endobj 2 0 obj<</Kids[3 0 R]/Count 1>>endobj 3 0 obj<</MediaBox[0 0 3 3]>>endobj\ntrailer<</Root 1 0 R>>")
os.system(f"evince {out_pdf}&")
cmds="&&".join([
f'rsync -av . {tmp_dir} --exclude=".*"',
f"cd {tmp_dir}",
f"latexmk -pdf {args.input} ",
f"cp {out_pdf} {pwd}/",
f"cd {pwd}"
])
os.system(f"nodemon --exec '{cmds}' -e 'tex bib' .")
os.system("rm -rf {tmp_dir}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment