Last active
August 16, 2020 18:42
-
-
Save giuliano-macedo/5334e8489e7b158b99c5c21e9cb29631 to your computer and use it in GitHub Desktop.
Move tex files and compiles them in a temp dir, then move pdf file to root. Works on linux and requires nodemon and latexmk
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 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