-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
diff.xsh
executable file
·90 lines (74 loc) · 2.89 KB
/
diff.xsh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env xonsh
# -*- mode: python -*-
"""Diffs the latex file and builds the pdf."""
import os
import sys
from argparse import ArgumentParser
$RAISE_SUBPROC_ERROR = True
# Uncomment this for debugging
# trace on
def replace_inputs(diffname, files):
with open(diffname, 'r') as fh:
s = fh.read()
for f in files:
fbase, _ = os.path.splitext(f)
s = s.replace('\\input{' + fbase + '}', '\\input{' + fbase + '-diff}')
s = s.replace('\\input{' + f + '}', '\\input{' + fbase + '-diff}')
with open(diffname, 'w') as fh:
fh.write(s)
def difftex(old):
files = set(`.*?\.tex`) - set(`.*?-diff\.tex`)
files -= {
'authors.tex',
'coverletter.tex',
'coverletter2.tex',
'rebuttal.tex',
'rebuttal2.tex',
}
new_files = set()
for f in files:
print('diffing ' + f)
fbase, fext = os.path.splitext(f)
oldspec = old + ':' + f
oldname = '/tmp/{0}-{1}{2}'.format(fbase, old, fext)
diffname = '{0}-diff{1}'.format(fbase, fext)
if f in new_files:
touch @(oldname)
else:
git show @(oldspec) > @(oldname)
latexdiff -c "PICTUREENV=(?:picture|DIFnomarkup|lstlisting)[\w\d*@]*" @(oldname) @(f) > @(diffname)
replace_inputs(diffname, files)
cp authors.tex authors-diff.tex
rm -rf /tmp/paper-diff
git clone @(os.path.dirname($ARG0)) /tmp/paper-diff
cwd = os.path.abspath(os.path.dirname($ARG0))
cd /tmp/paper-diff
git checkout @(old)
make paper.pdf supplement.pdf
cp /tmp/paper-diff/paper.bbl @(os.path.join(cwd, 'paper-' + old + '.bbl'))
cp /tmp/paper-diff/supplement.bbl @(os.path.join(cwd, 'supplement-' + old + '.bbl'))
cd @(cwd)
latexdiff @(os.path.join(cwd, 'paper-' + old + '.bbl')) paper.bbl > paper-diff.bbl
latexdiff @(os.path.join(cwd, 'supplement-' + old + '.bbl')) supplement.bbl > supplement-diff.bbl
# latexdiff @(os.path.join(cwd, 'supplement' + '.bbl')) supplement.bbl > supplement-diff.bbl
def fixes():
with open('comparison_with_mma-diff.tex') as f:
text = f.read()
with open('comparison_with_mma-diff.tex', 'w') as f:
f.write(text.replace('\\PAR', ''))
with open('supplement-diff.bbl') as f:
text = f.read()
with open('supplement-diff.bbl', 'w') as f:
f.write(text.replace(r'\DIFdelbegin %DIFDELCMD < \bibitem[Abramowitz and Stegun, 1964]{Abramowitz1964handbook}',
r'''\DIFdelbegin %DIFDELCMD <
\bibitem[Abramowitz and Stegun, 1964]{Abramowitz1964handbook}'''))
def main(args=None):
parser = ArgumentParser('diff')
parser.add_argument('old', help='Tree to compare against.')
parser.add_argument('--manuscript', help='Diffed manuscript name',
default='paper-diff.pdf', dest='manuscript')
ns = parser.parse_args(args=args or $ARGS[1:])
difftex(ns.old)
fixes()
if __name__ == '__main__':
main()