-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlatex-diff.py
51 lines (41 loc) · 1.29 KB
/
latex-diff.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import argparse
import glob
import os
import shutil
import subprocess
def main():
# CLI
descr = "Run latexdiff and generate a pdf"
parser = argparse.ArgumentParser(description=descr,
formatter_class=argparse.RawDescriptionHelpFormatter)
r1 = 'Starting commit/revision/tag.'
parser.add_argument('r1', help=r1)
r2 = 'Ending commit/revision/tag. Defaults to HEAD.'
parser.add_argument('--r2', help=r2, default='HEAD')
args = parser.parse_args()
# args from CLI
r1 = args.r1
r2 = args.r2
# save files
files = glob.glob('*.tex')
for f in files:
shutil.copyfile(f, '.' + f)
# generate diffs
cmd = "latexdiff-vc -r {} -r {}"
subprocess.check_call(cmd.format(r1, r2).split() + files)
# build pdf
diff_file = lambda f, r1, r2: "{}-diff{}-{}.{}".format(
f[:-4], r1, r2, f[-3:])
for f in files:
shutil.copyfile(diff_file(f, r1, r2), f)
subprocess.check_call('make')
shutil.copyfile('paper.pdf', diff_file('paper.pdf', r1, r2))
# clean up
for f in files:
shutil.copyfile('.' + f, f)
rm = glob.glob(diff_file('*.tex', r1, r2)) + glob.glob('*oldtmp*.tex')
for f in set(rm):
os.remove(f)
if __name__ == '__main__':
main()