taesiri commited on
Commit
b2272b8
β€’
1 Parent(s): 528d8e8

initial commit

Browse files
Files changed (6) hide show
  1. LICENSE +21 -0
  2. README.md +3 -3
  3. app.py +46 -0
  4. git-latexdiff +951 -0
  5. packages.txt +8 -0
  6. requirements.txt +2 -0
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Mohammad Reza Taesiri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: LatexDiff
3
- emoji: ⚑
4
  colorFrom: pink
5
- colorTo: pink
6
  sdk: gradio
7
  app_file: app.py
8
  pinned: false
1
  ---
2
+ title: GitLatexDiff
3
+ emoji: πŸš€
4
  colorFrom: pink
5
+ colorTo: yellow
6
  sdk: gradio
7
  app_file: app.py
8
  pinned: false
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import git
3
+ import tempfile
4
+ import shutil
5
+ import subprocess
6
+ import os
7
+
8
+ cwd = os.getcwd()
9
+ gcounter = 1000
10
+
11
+ def generate_git(OldVersion, NewVersion, tmp_dir_name):
12
+ new_repo = git.Repo.init(tmp_dir_name)
13
+ with new_repo.config_writer() as git_config:
14
+ git_config.set_value('user', 'email', 'latexdiff@latexdiff.latexdiff')
15
+ git_config.set_value('user', 'name', 'git Latex Diff')
16
+
17
+ shutil.unpack_archive(OldVersion.name, tmp_dir_name)
18
+
19
+ new_repo.index.add('*')
20
+ new_repo.index.commit('Initial commit.')
21
+
22
+ shutil.unpack_archive(NewVersion.name, tmp_dir_name)
23
+
24
+ new_repo.index.add('*')
25
+ new_repo.index.commit('Changes')
26
+
27
+ def generate_diff(tmp_dir_name):
28
+ subprocess.check_call([f'{cwd}/git-latexdiff', 'HEAD~1', '--cleanup', 'keeppdf', '-o', 'mydiff.pdf'], cwd=tmp_dir_name)
29
+
30
+ def gen_all(OldVersion, NewVersion):
31
+ global gcounter
32
+ gcounter+=1
33
+
34
+ dirpath = tempfile.mkdtemp()
35
+ fake_git_name = 'something'
36
+ generate_git(OldVersion, NewVersion, dirpath)
37
+ generate_diff(dirpath)
38
+ shutil.move(f'{dirpath}/mydiff.pdf', f'{cwd}/results/{gcounter}.pdf')
39
+ shutil.rmtree(dirpath)
40
+
41
+ return f'{cwd}/results/{gcounter}.pdf'
42
+
43
+ os.makedirs('results', exist_ok=True)
44
+
45
+ iface = gr.Interface(gen_all, ["file", "file"], "file", allow_screenshot=False, allow_flagging=False)
46
+ iface.launch(enable_queue=True)
git-latexdiff ADDED
@@ -0,0 +1,951 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #! /bin/bash
2
+
3
+ # Main author: Matthieu Moy <git@matthieu-moy.fr>
4
+ # (See the Git history for other contributors)
5
+ #
6
+ # BSD 2-Clause License
7
+ #
8
+ # Copyright (c) 2012 - 2020, Matthieu Moy
9
+ # All rights reserved.
10
+ #
11
+ # Redistribution and use in source and binary forms, with or without
12
+ # modification, are permitted provided that the following conditions are met:
13
+ #
14
+ # 1. Redistributions of source code must retain the above copyright notice, this
15
+ # list of conditions and the following disclaimer.
16
+ #
17
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
18
+ # this list of conditions and the following disclaimer in the documentation
19
+ # and/or other materials provided with the distribution.
20
+ #
21
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ # git-latexdiff is a wrapper around latexdiff
33
+ # (http://www.ctan.org/pkg/latexdiff) that allows using it to diff two
34
+ # revisions of a LaTeX file.
35
+ #
36
+ # The script internally checks out the full tree for the specified
37
+ # revisions, calls latexpand to flatten the document and then calls
38
+ # latexdiff-so (if available, otherwise latexdiff). Therefore,
39
+ # this works if the document is split into multiple .tex files.
40
+ #
41
+ # Try "git latexdiff -h" for more information.
42
+ #
43
+ # To install, just copy git-latexdiff in your $PATH.
44
+
45
+ # Missing features (patches welcome ;-):
46
+ # - diff the index
47
+ # - hardlink temporary checkouts as much as possible
48
+
49
+ # Alternatives:
50
+ #
51
+ # There is another script doing essentially the same here:
52
+ # https://github.com/cawka/latexdiff/blob/master/latexdiff-git
53
+ # My experience is that latexdiff-git is more buggy than
54
+ # git-latexdiff, but they probably just don't have the same bugs ;-)
55
+ #
56
+ # There are a bunch of other alternatives cited here:
57
+ #
58
+ # http://tex.stackexchange.com/questions/1325/using-latexdiff-with-git
59
+ #
60
+ # Ideally, these scripts should be merged.
61
+
62
+ set -o errexit
63
+ set -o pipefail
64
+ set -o noclobber
65
+ # Used when symlinking files from the working tree: symlink .* files
66
+ # too.
67
+ shopt -s dotglob
68
+
69
+ # Some versions of git set $GIT_WORK_TREE when ran through an alias.
70
+ # This wouldn't work with git-latexdiff which plays with different
71
+ # work trees.
72
+ unset GIT_DIR
73
+ unset GIT_WORK_TREE
74
+
75
+ # (Comment and 'unset' line borrowed from Git's source code)
76
+ # Having this variable in your environment would break scripts because
77
+ # you would cause "cd" to be taken to unexpected places. If you
78
+ # like CDPATH, define it for your interactive shell sessions without
79
+ # exporting it.
80
+ # But we protect ourselves from such a user mistake nevertheless.
81
+ unset CDPATH
82
+
83
+ # @GIT_LATEXDIFF_VERSION@ is substituted by the install script here,
84
+ # but not within git_latexdiff_compute_version().
85
+ git_latexdiff_version='@GIT_LATEXDIFF_VERSION@'
86
+
87
+ git_latexdiff_compute_version () {
88
+ printf '%s' "git latexdiff version "
89
+ if [ "$git_latexdiff_version" = '@GIT_LATEXDIFF''_VERSION@' ]; then
90
+ (cd "$(dirname "$0")" && git describe --tags HEAD 2>/dev/null || echo 'Unknown version')
91
+ else
92
+ echo "$git_latexdiff_version"
93
+ fi
94
+ echo
95
+ echo "Using external commands:"
96
+ command -v latexpand && latexpand --version
97
+ command -v latexdiff && latexdiff --version
98
+ }
99
+
100
+ usage () {
101
+ cat << EOF
102
+ Usage: $(basename "$0" | sed 's/git-/git /') [options] OLD [NEW]
103
+ $(basename "$0" | sed 's/git-/git /') [options] OLD --
104
+ $(basename "$0" | sed 's/git-/git /') [options] -- OLD
105
+ Call latexdiff on two Git revisions of a file.
106
+
107
+ OLD and NEW are Git revision identifiers. NEW defaults to HEAD.
108
+ If "--" is used for NEW, then diff against the working directory.
109
+
110
+ Options:
111
+ --help this help message
112
+ --help-examples show examples of usage
113
+ --main <file> name of the main LaTeX, R Sweave,
114
+ or Emacs Org mode file.
115
+ The search for the only file containing 'documentclass'
116
+ will be attempted, if not specified.
117
+ For non-LaTeX files, a reasonable \`prepare\` command
118
+ will be used unless explicitly provided
119
+ --no-view don't display the resulting PDF file
120
+ --latex run latex instead of pdflatex
121
+ --xelatex run xelatex instead of pdflatex
122
+ --lualatex run lualatex instead of pdflatex
123
+ --tectonic run tectonic instead of pdflatex
124
+ --bibtex, --bbl display changes in the bibliography
125
+ (runs bibtex to generate *.bbl files and
126
+ include them in the source file using
127
+ latexpand --expand-bbl before computing
128
+ the diff)
129
+ --biber like --bibtex, but runs biber instead.
130
+ --run-bibtex, -b run bibtex as well as latex to generate the PDF file
131
+ (pdflatex,bibtex,pdflatex,pdflatex)
132
+ NOTE: --bibtex usually works better
133
+ --run-biber run BibLaTex-Biber as well as latex to generate the PDF file
134
+ (pdflatex,biber,pdflatex,pdflatex)
135
+ NOTE: --biber usually works better
136
+ --view view the resulting PDF file
137
+ (default if -o is not used)
138
+ --pdf-viewer <cmd> use <cmd> to view the PDF file (default: \$PDFVIEWER)
139
+ --no-cleanup don't cleanup temp dir after running
140
+ --no-flatten don't call latexpand to flatten the document
141
+ --cleanup MODE Cleanup temporary files according to MODE:
142
+
143
+ - keeppdf (default): keep only the
144
+ generated PDF file
145
+
146
+ - none: keep all temporary files
147
+ (may eat your diskspace)
148
+
149
+ - all: erase all generated files.
150
+ Problematic with --view when the
151
+ viewer is e.g. evince, and doesn't
152
+ like when the file being viewed is
153
+ deleted.
154
+
155
+ --latexmk use latexmk
156
+ --build-dir use pdfs from specific build directory
157
+ --latexopt pass additional options to latex (e.g. -shell-escape)
158
+ -o <file>, --output <file>
159
+ copy resulting PDF into <file> (usually ending with .pdf)
160
+ Implies "--cleanup all"
161
+ --tmpdirprefix where temporary directory will be created (default: /tmp).
162
+ Relative path will use repository root as a base
163
+ --verbose, -v give more verbose output
164
+ --quiet redirect output from subprocesses to log files
165
+ --prepare <cmd> run <cmd> before latexdiff (e.g. run make to generate
166
+ included files)
167
+ --filter <cmd> run <cmd> after latexdiff and before compilation
168
+ (e.g. to fix up latexdiff output)
169
+ --ln-untracked symlink uncommited files from the working directory
170
+ --version show git-latexdiff version.
171
+ --subtree checkout the tree at and below the main file
172
+ (enabled by default, disable with --whole-tree)
173
+ --whole-tree checkout the whole tree (contrast with --subtree)
174
+ --ignore-latex-errors keep on going even if latex gives errors, so long as
175
+ a PDF file is produced
176
+ --ignore-makefile ignore the Makefile, build as though it doesn't exist
177
+ -* other options are passed directly to latexdiff
178
+ --latexpand OPT pass option OPT to latexpand. Use multiple times like
179
+ --latexpand OPT1 --latexpand OPT2 to pass multiple options.
180
+ --latexdiff-flatten use --flatten from latexdiff instead of latexpand
181
+
182
+ Unrecognized options are passed unmodified to latexdiff.
183
+ EOF
184
+ }
185
+
186
+ examples () {
187
+ cat <<EOF
188
+ Diff the previous revision with the latest commit:
189
+
190
+ git latexdiff HEAD^
191
+
192
+ Diff the latest commit with the working tree:
193
+
194
+ git latexdiff HEAD --
195
+
196
+ Diff latest commit with branch master:
197
+
198
+ git latexdiff master HEAD
199
+
200
+ Pass --type=CHANGEBAR to latexdiff to get changebars in the margins
201
+ instead of red+trike/blue+underline diff:
202
+
203
+ git latexdiff --type=CHANGEBAR HEAD^
204
+
205
+ Use a specific latexdiff configuration file:
206
+
207
+ git latexdiff --config /path/to/file HEAD^
208
+
209
+ Add a \\makeatletter statement to hopefuly fix some LaTeX compilation errors
210
+ involving commands containing an @ character:
211
+
212
+ git latexdiff --latexpand --makeatletter HEAD^
213
+ EOF
214
+ }
215
+
216
+ die () {
217
+ echo "fatal: $*"
218
+ exit 1
219
+ }
220
+
221
+ verbose () {
222
+ if test "$verbose" = 1 ; then
223
+ printf "%s ..." "$@"
224
+ fi
225
+ }
226
+
227
+ verbose_progress () {
228
+ if test "$verbose" = 1 ; then
229
+ printf "."
230
+ fi
231
+ }
232
+
233
+ verbose_done () {
234
+ if test "$verbose" = 1 ; then
235
+ echo " ${1:-done}."
236
+ fi
237
+ }
238
+
239
+ verbose_say () {
240
+ if test "$verbose" = 1 ; then
241
+ printf "%s\n" "$@"
242
+ fi
243
+ }
244
+
245
+ old=
246
+ new=
247
+ main=
248
+ view=maybe
249
+ cleanup=keeppdf
250
+ verbose=0
251
+ bibtex=0
252
+ biber=0
253
+ output=
254
+ initial_dir=$PWD
255
+ tmpdir_prefix="/tmp"
256
+ prepare_cmd=
257
+ flatten=1
258
+ subtree=1
259
+ uselatexmk=
260
+ use_build_dir=
261
+ latexopt=
262
+ ln_untracked=0
263
+ quiet=0
264
+ ignorelatexerrors=0
265
+ latexdiffopt=()
266
+ latexpand=()
267
+ bbl=0
268
+ latexdiff_flatten=0
269
+ latex=0
270
+ xelatex=0
271
+ lualatex=0
272
+ tectonic=0
273
+ BIBTEX_EXEC=bibtex
274
+
275
+ while test $# -ne 0; do
276
+ case "$1" in
277
+ "--help"|"-h")
278
+ usage
279
+ exit 0
280
+ ;;
281
+ "--help-examples")
282
+ examples
283
+ exit 0
284
+ ;;
285
+ "--main")
286
+ test $# -gt 1 && shift || die "missing argument for $1"
287
+ main=$1
288
+ ;;
289
+ "--no-view")
290
+ view=0
291
+ ;;
292
+ "--view")
293
+ view=1
294
+ ;;
295
+ "--pdf-viewer")
296
+ test $# -gt 1 && shift || die "missing argument for $1"
297
+ PDFVIEWER="$1"
298
+ ;;
299
+ "--no-cleanup")
300
+ cleanup=none
301
+ ;;
302
+ "--ignore-latex-errors")
303
+ ignorelatexerrors=1
304
+ ;;
305
+ "--cleanup")
306
+ shift
307
+ case "$1" in
308
+ "none"|"all"|"keeppdf")
309
+ cleanup="$1"
310
+ ;;
311
+ *)
312
+ echo "Bad argument --cleanup $1"
313
+ usage
314
+ exit 1
315
+ ;;
316
+ esac
317
+ ;;
318
+ "--no-flatten")
319
+ flatten=0
320
+ ;;
321
+ "--ignore-makefile")
322
+ ignoremake=1
323
+ ;;
324
+ "-o"|"--output")
325
+ test $# -gt 1 && shift || die "missing argument for $1"
326
+ output=$1
327
+ cleanup=all
328
+ ;;
329
+ "-b"|"--bibtex")
330
+ bbl=1
331
+ ;;
332
+ "--latex")
333
+ latex=1
334
+ ;;
335
+ "--xelatex")
336
+ xelatex=1
337
+ ;;
338
+ "--lualatex")
339
+ lualatex=1
340
+ ;;
341
+ "--tectonic")
342
+ tectonic=1
343
+ ;;
344
+ "--biber")
345
+ BIBTEX_EXEC=biber
346
+ bbl=1
347
+ ;;
348
+ "--run-bibtex")
349
+ bibtex=1
350
+ ;;
351
+ "--run-biber")
352
+ biber=1
353
+ ;;
354
+ "--verbose"|"-v")
355
+ verbose=1
356
+ ;;
357
+ "--quiet")
358
+ quiet=1
359
+ ;;
360
+ "--version")
361
+ git_latexdiff_compute_version
362
+ exit 0
363
+ ;;
364
+ "--subtree")
365
+ subtree=1
366
+ ;;
367
+ "--whole-tree")
368
+ subtree=0
369
+ ;;
370
+ "--prepare")
371
+ shift
372
+ prepare_cmd="$1"
373
+ ;;
374
+ "--filter")
375
+ shift
376
+ filter_cmd="$1"
377
+ ;;
378
+ "--build-dir")
379
+ test $# -gt 1 && shift || die "missing argument for $1"
380
+ use_build_dir=$1
381
+ ;;
382
+ "--latexmk")
383
+ uselatexmk=1
384
+ ;;
385
+ "--latexpand")
386
+ shift
387
+ latexpand=("${latexpand[@]}" "$1")
388
+ ;;
389
+ "--bbl")
390
+ bbl=1
391
+ ;;
392
+ "--latexdiff-flatten")
393
+ latexdiff_flatten=1
394
+ flatten=0
395
+ ;;
396
+ "--latexopt")
397
+ shift
398
+ latexopt=$1
399
+ ;;
400
+ "--ln-untracked")
401
+ ln_untracked=1
402
+ ;;
403
+ "--no-ln-untracked")
404
+ ln_untracked=0
405
+ ;;
406
+ "--tmpdirprefix")
407
+ shift
408
+ tmpdir_prefix="$1"
409
+ ;;
410
+ -*)
411
+ if test "$1" = "--" ; then
412
+ if test -z "$new" ; then
413
+ new=$1
414
+ else
415
+ echo "Bad argument $1"
416
+ usage
417
+ exit 1
418
+ fi
419
+ else
420
+ case "$1" in
421
+ '--type'|'-t'|'--subtype'|'-s'|'--floattype'|'-f'|\
422
+ '--config'|'-c'|'--encoding'|'-e'|\
423
+ '--label'|'-L'|'--exclude-safecmd'|'-A'|\
424
+ '--replace-safecmd'|'--append-safecmd'|'-a'|\
425
+ '--exclude-textcmd'|'-X'|'--replace-textcmd'|\
426
+ '--append-textcmd'|'-x'|'--replace-context1cmd'|\
427
+ '--append-context1cmd'|'--replace-context2cmd'|\
428
+ '--append-context2cmd'|'--packages'|'--math-markup'|\
429
+ '--driver')
430
+ # Options taking an immediate argument in
431
+ # latexdiff => add both the option and its
432
+ # argument.
433
+ latexdiffopt+=("$1" "$2")
434
+ shift
435
+ ;;
436
+ --preamble=*|-p*|"--preamble"|"-p")
437
+ # Same, but with a file argument. Make it
438
+ # absolute to avoid issues when cd-ing
439
+ # somewhere else.
440
+ doshift=1
441
+ if test "$1" = "--preamble" || test "$1" = "-p"; then
442
+ relative="$2"
443
+ else
444
+ relative="$(printf "%s" "$1" | sed 's/^--preamble=//;s/^-p//')"
445
+ doshift=0
446
+ fi
447
+ absolute="$(cd $(dirname "$relative"); pwd)/$(basename "$relative")"
448
+ latexdiffopt+=("-p" "$absolute")
449
+ if test $doshift = 1; then
450
+ shift
451
+ fi
452
+ ;;
453
+ *)
454
+ latexdiffopt+=("$1")
455
+ ;;
456
+ esac
457
+ fi
458
+ ;;
459
+ *)
460
+ if test -z "$1" ; then
461
+ echo "Empty string not allowed as argument"
462
+ usage
463
+ exit 1
464
+ elif test -z "$old" ; then
465
+ old=$1
466
+ elif test -z "$new" ; then
467
+ new=$1
468
+ else
469
+ echo "Bad argument $1"
470
+ usage
471
+ exit 1
472
+ fi
473
+ ;;
474
+ esac
475
+ shift
476
+ done
477
+
478
+ initial_repo=$(git rev-parse --show-toplevel)
479
+
480
+ if test -z "$new" ; then
481
+ new=HEAD
482
+ fi
483
+
484
+ if test -z "$old" ; then
485
+ echo "fatal: Please, provide at least one revision to diff with."
486
+ usage
487
+ exit 1
488
+ fi
489
+
490
+ if test -z "$PDFVIEWER" ; then
491
+ verbose "Auto-detecting PDF viewer"
492
+ candidates="xdg-open evince okular xpdf acroread"
493
+ if test "$(uname)" = Darwin ; then
494
+ # open exists on GNU/Linux, but does not open PDFs
495
+ candidates="open $candidates"
496
+ fi
497
+
498
+ for command in $candidates; do
499
+ if command -v "$command" >/dev/null 2>&1; then
500
+ PDFVIEWER="$command"
501
+ break
502
+ else
503
+ verbose_progress
504
+ fi
505
+ done
506
+ verbose_done "$PDFVIEWER"
507
+ fi
508
+
509
+ case "$view" in
510
+ maybe|1)
511
+ if test -z "$PDFVIEWER" ; then
512
+ echo "warning: could not find a PDF viewer on your system."
513
+ echo "warning: Please set \$PDFVIEWER or use --pdf-viewer CMD."
514
+ PDFVIEWER=false
515
+ fi
516
+ ;;
517
+ esac
518
+
519
+ if test $flatten = 1 &&
520
+ ! command -v latexpand >/dev/null 2>&1; then
521
+ echo "Warning: latexpand not found. Falling back to latexdiff --flatten."
522
+ latexdiff_flatten=1
523
+ flatten=0
524
+ fi
525
+
526
+ if test $latex = 1; then
527
+ LATEX_EXEC=latex
528
+ elif test $xelatex = 1; then
529
+ LATEX_EXEC=xelatex
530
+ elif test $lualatex = 1; then
531
+ LATEX_EXEC=lualatex
532
+ elif test $tectonic = 1; then
533
+ LATEX_EXEC=tectonic
534
+ else
535
+ LATEX_EXEC=pdflatex
536
+ fi
537
+
538
+ if test $biber = 1; then
539
+ BIBTEX_EXEC=biber
540
+ fi
541
+
542
+ ## end option parsing ##
543
+
544
+ check_knitr () {
545
+ if test -z "$prepare_cmd"; then
546
+ prepare_cmd="Rscript -e \"library(knitr); knit('$main')\""
547
+ fi
548
+ main="${main%\.*}.tex"
549
+ }
550
+
551
+ check_org () {
552
+ if test -z "$prepare_cmd"; then
553
+ init_file=
554
+ load_init_file=
555
+ for f in ~/.emacs ~/.emacs.el ~/.emacs.d/init.elc ~/.emacs.d/init.el; do
556
+ if test -f "$f"; then
557
+ init_file="$f"
558
+ break
559
+ fi
560
+ done
561
+ if test -n "$init_file"; then
562
+ load_init_file="--eval \"(load \\\"$init_file\\\")\""
563
+ fi
564
+ prepare_cmd="emacs --batch $load_init_file \"$main\" -f org-latex-export-to-latex --kill"
565
+ fi
566
+ main="${main%\.*}.tex"
567
+ }
568
+
569
+ log_cmd () {
570
+ log=$1
571
+ shift
572
+ if [ "$quiet" = 1 ]; then
573
+ "$@" >$log 2>&1
574
+ else
575
+ "$@"
576
+ fi
577
+ }
578
+
579
+ # main is relative to initial_dir (if returned)
580
+ if test -z "$main" ; then
581
+ printf "%s" "No --main provided, trying to guess ... "
582
+ main=$(git grep -l '^[ \t]*\\documentclass')
583
+ # May return multiple results, but if so the result won't be a file.
584
+ if test -r "$main" ; then
585
+ echo "Using $main as the main file."
586
+ else
587
+ if test -z "$main" ; then
588
+ echo "No candidate for main file."
589
+ else
590
+ echo "Multiple candidates for main file:"
591
+ printf "%s\n" "$main" | sed 's/^/\t/'
592
+ fi
593
+ die "Please, provide a main file with --main FILE.tex."
594
+ fi
595
+ fi
596
+
597
+ if test ! -r "$main" ; then
598
+ die "Cannot read $main."
599
+ fi
600
+
601
+ ext=${main##*\.}
602
+ case "$ext" in
603
+ Rnw) check_knitr ;;
604
+ Rtex) check_knitr ;;
605
+ org) check_org ;;
606
+ *) ;;
607
+ esac
608
+
609
+ # Set LATEXDIFF_EXEC to either latexdiff or latexdiff-so. Prefer
610
+ # latexdiff-so if available.
611
+ if command -v latexdiff-so >/dev/null 2>&1; then
612
+ LATEXDIFF_EXEC=latexdiff-so
613
+ elif command -v latexdiff >/dev/null 2>&1; then
614
+ LATEXDIFF_EXEC=latexdiff
615
+ else
616
+ die "latexdiff-so and latexdiff couldn't be found. Check your PATH."
617
+ fi
618
+ verbose_done "$LATEXDIFF_EXEC"
619
+
620
+ verbose "Creating temporary directories"
621
+
622
+ git_prefix=$(git rev-parse --show-prefix)
623
+ git_dir="$(git rev-parse --git-dir)" || die "Not a git repository?"
624
+ cd "$(git rev-parse --show-cdup)" || die "Can't cd back to repository root"
625
+ git_dir=$(cd "$git_dir"; pwd)
626
+ git_worktree=$(pwd)
627
+
628
+ relative_main_dir=$(dirname "$main")
629
+ # make main relative to git root directory
630
+ if test -n "$git_prefix" ; then
631
+ main=$git_prefix$main
632
+ fi
633
+ mainbase=$(basename "$main" .tex)
634
+ maindir=$(dirname "$main")
635
+
636
+ tmpdir=$tmpdir_prefix/git-latexdiff.$$
637
+ mkdir "$tmpdir" || die "Cannot create temporary directory."
638
+
639
+ cd "$tmpdir" || die "Cannot cd to $tmpdir"
640
+ if test "$(uname -o 2>/dev/null)" = "Msys"; then
641
+ tmpdir=$(pwd -W)
642
+ else
643
+ tmpdir=$(pwd)
644
+ fi
645
+
646
+ mkdir old new || die "Cannot create old and new directories."
647
+
648
+ verbose_done
649
+ verbose_say "Temporary directories: $tmpdir/old and $tmpdir/new"
650
+ verbose "Checking out old and new version"
651
+
652
+ cd old || die "Cannot cd to old/"
653
+ if test "$ln_untracked" = 1; then
654
+ (
655
+ mkdir -p "$maindir" && cd "$maindir" &&
656
+ log_cmd ln-old.log ln -s "$initial_repo"/"$maindir"/* .
657
+ ) || true
658
+ fi
659
+
660
+ if test "$subtree" = 1 && test -n "$git_prefix"; then
661
+ checkoutroot=$git_prefix
662
+ else
663
+ checkoutroot="./"
664
+ fi
665
+ # create the build directory (containing the final PDFs) if the param was set
666
+ if test -n "$use_build_dir" ; then
667
+ builddir="$use_build_dir"
668
+ else
669
+ builddir="$relative_main_dir"
670
+ fi
671
+
672
+ # Checkout a subtree, without touching the index ("git checkout" would)
673
+ (cd "$git_dir" && git archive --format=tar "$old" "$checkoutroot") | tar -xf -
674
+ # Also expand the possible submodules
675
+ (cd "$git_worktree" && git ls-tree "$old":"$checkoutroot" | \
676
+ { grep '^[^ ]* commit ' || true; } | \
677
+ while read -r mod type id name; do
678
+ # Submodule's object may be in the submodule (if it was directly "git init && git add"-ed),
679
+ # or in .git/modules, if it was cloned using "git submodule update <repository> <path>".
680
+ ALTERNATES=
681
+ for d in "$name"/.git/objects/ .git/modules/"$name"/objects/; do
682
+ if test -d "$d"; then
683
+ ALTERNATES="$ALTERNATES":"$d"
684
+ fi
685
+ done
686
+ GIT_ALTERNATE_OBJECT_DIRECTORIES="$GIT_ALTERNATE_OBJECT_DIRECTORIES":"$ALTERNATES" \
687
+ git archive --format=tar "$id"^{tree} | tar -xf - --directory "$tmpdir/old/$name"
688
+ done
689
+ )
690
+ verbose_progress
691
+ cd ../new || die "Cannot cd to new/"
692
+ if test "$new" == "--"; then
693
+ # Copy working tree files
694
+ (cd "$git_worktree" && git ls-files -- "$checkoutroot" | tar -cf - -T -) | tar -xf -
695
+ else
696
+ # checkout new revision
697
+ (cd "$git_dir" && git archive --format=tar "$new" "$checkoutroot") | tar -xf -
698
+ # In case the submodule isn't yet "git add && git commit"ed, its directory may not have been created.
699
+ (cd "$git_worktree" && git submodule foreach --recursive 'mkdir -p '$tmpdir/new'/$displaypath')
700
+ (cd "$git_worktree" && git submodule foreach --recursive 'git archive --format=tar "$sha1" | tar -xf - --directory '$tmpdir/new'/$displaypath')
701
+ fi
702
+ if test "$ln_untracked" = 1; then
703
+ (
704
+ mkdir -p "$maindir" && cd "$maindir" &&
705
+ log_cmd ln-new.log ln -s "$initial_repo"/"$maindir"/* .
706
+ ) || true
707
+ fi
708
+
709
+ verbose_progress
710
+ cd ..
711
+
712
+ verbose_done
713
+
714
+ for dir in old new
715
+ do
716
+ verbose "Running preparation command $prepare_cmd in $dir/$git_prefix"
717
+ ( cd "$dir/$git_prefix/" && log_cmd prepare.log eval "$prepare_cmd" )
718
+ if test ! -f "$dir/$main"; then
719
+ die "$prepare_cmd did not produce $dir/$main."
720
+ fi
721
+ verbose_done
722
+ done
723
+
724
+ if test $tectonic != 1; then
725
+ if [ "$ignorelatexerrors" = 1 ]; then
726
+ latexopt="$latexopt -interaction=batchmode"
727
+ elif [ "$quiet" = 1 ]; then
728
+ latexopt="$latexopt -interaction=nonstopmode"
729
+ else
730
+ latexopt="$latexopt -interaction=errorstopmode"
731
+ fi
732
+ fi
733
+
734
+ # Option to use latexdiff --flatten instead of latexpand
735
+ if test "$latexdiff_flatten" = 1; then
736
+ latexdiffopt+=("--flatten")
737
+ fi
738
+
739
+ # Shortcut to include bbl
740
+ if test "$bbl" = 1; then
741
+ if test "$biber" = 1; then
742
+ bblexpand=("--expand-bbl" "$mainbase.bbl")
743
+ # In theory, this (with recent enough latexpand) should work
744
+ # better. In practice it doesn't seem to work though.
745
+ # bblexpand=("--biber" "$mainbase.bbl")
746
+ else
747
+ bblexpand=("--expand-bbl" "$mainbase.bbl")
748
+ fi
749
+ else
750
+ bblexpand=()
751
+ fi
752
+
753
+ ignore_errors_maybe() {
754
+ if [ "$compile_error" = 1 ] && [ "$ignorelatexerrors" = 1 ]; then
755
+ echo "LaTeX errors were found - but attempting to carry on."
756
+ compile_error=0
757
+ fi
758
+ }
759
+
760
+ # Create flattened documents and keep for debugging
761
+ if test "$flatten" = 1; then
762
+ if [ "$bbl" = 1 ]; then
763
+ if [ ! -f "old/$maindir$mainbase.bbl" ]; then
764
+ verbose "Attempting to regenerate missing old/$maindir$mainbase.bbl"
765
+ oldPWD=$PWD
766
+ cd old/"$maindir"
767
+ log_cmd pdflatex0.log $LATEX_EXEC $latexopt "$mainbase" || {
768
+ compile_error=1
769
+ error_msg="command 'pdflatex' (automatically run in old due to --bbl) failed."
770
+ }
771
+ log_cmd "$BIBTEX_EXEC"0.log $BIBTEX_EXEC "$mainbase" || {
772
+ compile_error=1
773
+ error_msg="command '$BIBTEX_EXEC' (automatically run in old due to --bbl) failed."
774
+ }
775
+ cd "$oldPWD"
776
+ ignore_errors_maybe
777
+ if [ "$compile_error" = 1 ]; then
778
+ die "Failed to regenerate .bbl for old version"
779
+ fi
780
+ fi
781
+ if [ ! -f "new/$maindir$mainbase.bbl" ]; then
782
+ verbose "Attempting to regenerate missing new/$maindir$mainbase.bbl"
783
+ oldPWD=$PWD
784
+ cd new/"$maindir"
785
+ log_cmd pdflatex0.log $LATEX_EXEC $latexopt "$mainbase" || {
786
+ compile_error=1
787
+ error_msg="command 'pdflatex' (automatically run in new due to --bbl) failed."
788
+ }
789
+ log_cmd "$BIBTEX_EXEC"0.log $BIBTEX_EXEC "$mainbase" || {
790
+ compile_error=1
791
+ error_msg="command '$BIBTEX_EXEC' (automatically run in new due to --bbl) failed."
792
+ }
793
+ cd "$oldPWD"
794
+ ignore_errors_maybe
795
+ if [ "$compile_error" = 1 ]; then
796
+ die "Failed to regenerate .bbl for new version"
797
+ fi
798
+ fi
799
+ fi
800
+ verbose "Running latexpand"
801
+ (
802
+ cd old/"$maindir" &&
803
+ latexpand "$mainbase".tex "${latexpand[@]}" "${bblexpand[@]}"
804
+ ) > old-"$mainbase"-fl.tex \
805
+ || die "latexpand failed for old version"
806
+ (
807
+ cd new/"$maindir" &&
808
+ latexpand "$mainbase".tex "${latexpand[@]}" "${bblexpand[@]}"
809
+ ) > new-"$mainbase"-fl.tex \
810
+ || die "latexpand failed for new version"
811
+ verbose_done
812
+
813
+ verbose "Running $LATEXDIFF_EXEC ${latexdiffopt[*]} old-${mainbase}-fl.tex new-${mainbase}-fl.tex > ./diff.tex"
814
+ "$LATEXDIFF_EXEC" "${latexdiffopt[@]}" old-"$mainbase"-fl.tex new-"$mainbase"-fl.tex > diff.tex \
815
+ || die "$LATEXDIFF_EXEC failed"
816
+ verbose_done
817
+
818
+ verbose "mv ./diff.tex new/$main"
819
+ mv -f new/"$main" new/"$main".orig
820
+ mv -f diff.tex new/"$main"
821
+ verbose_done
822
+ else
823
+ verbose "Running $LATEXDIFF_EXEC ${latexdiffopt[*]} old/$main new/$main > ./diff.tex"
824
+ "$LATEXDIFF_EXEC" "${latexdiffopt[@]}" old/"$main" new/"$main" > diff.tex \
825
+ || die "$LATEXDIFF_EXEC failed"
826
+ verbose_done
827
+
828
+ verbose "mv ./diff.tex new/$main"
829
+ mv -f new/"$main" new/"$main.orig"
830
+ mv -f diff.tex new/"$main"
831
+ verbose_done
832
+ fi
833
+
834
+ if [ ! -z "$filter_cmd" ]; then
835
+ verbose "Running filter command $filter_cmd in new/"
836
+ ( cd "new/" && log_cmd filter.log eval "$filter_cmd" )
837
+ if [ ! -f "new/$main" ]; then
838
+ die "$filter_cmd removed new/$main."
839
+ fi
840
+ verbose_done
841
+ fi
842
+
843
+ verbose "Compiling result"
844
+
845
+ compile_error=0
846
+
847
+ oldPWD=$PWD
848
+ cd new/"$maindir" || die "Can't cd to new/$maindir"
849
+ if test -e Makefile && test "$ignoremake" != 1 ; then
850
+ log_cmd make.log make || {
851
+ compile_error=1
852
+ error_msg="command 'make' failed."
853
+ }
854
+ elif test "$uselatexmk" = 1; then
855
+ log_cmd latexmk.log latexmk -f -pdf -silent $latexopt "$mainbase" || {
856
+ compile_error=1
857
+ error_msg="command 'latexmk' failed."
858
+ }
859
+ elif test "$tectonic" = 1; then
860
+ log_cmd tectonic.log tectonic $latexopt "$mainbase.tex" || {
861
+ compile_error=1
862
+ error_msg="command 'tectonic' failed."
863
+ }
864
+ else
865
+ log_cmd pdflatex1.log $LATEX_EXEC $latexopt "$mainbase" || {
866
+ compile_error=1
867
+ error_msg="command pdflatex (first run) failed."
868
+ }
869
+ if test "$bibtex" = 1 || test "$biber" = 1 ; then
870
+ log_cmd "$BIBTEX_EXEC".log $BIBTEX_EXEC "$mainbase" || {
871
+ compile_error=1
872
+ error_msg="command '$BIBTEX_EXEC' failed."
873
+ }
874
+ fi
875
+ log_cmd pdflatex2.log $LATEX_EXEC $latexopt "$mainbase" || {
876
+ compile_error=1
877
+ error_msg="command 'pdflatex' (second run) failed."
878
+ }
879
+ log_cmd pdflatex3.log $LATEX_EXEC $latexopt "$mainbase" || {
880
+ compile_error=1
881
+ error_msg="command 'pdflatex' (third run) failed."
882
+ }
883
+ fi
884
+ cd "$oldPWD"
885
+
886
+ # Same relative path as where we've been called from, but in the
887
+ # temporary new/ directory:
888
+ cd new/"$git_prefix"
889
+
890
+ verbose_done
891
+
892
+ ignore_errors_maybe
893
+
894
+ if test $latex = 1; then
895
+ dvips "$mainbase".dvi
896
+ ps2pdf "$mainbase".ps
897
+ fi
898
+
899
+ pdffile="$builddir/$mainbase".pdf
900
+ if test ! -r "$pdffile" ; then
901
+ echo "No PDF file generated."
902
+ echo "Working directory: $PWD"
903
+ echo "Expected PDF: $pdffile"
904
+ compile_error=1
905
+ elif test ! -s "$pdffile" ; then
906
+ echo "PDF file generated is empty."
907
+ compile_error=1
908
+ fi
909
+
910
+ if test "$compile_error" = "1" ; then
911
+ echo "Error during compilation. Please examine and cleanup if needed:"
912
+ echo "Directory: $tmpdir/new/$maindir"
913
+ echo " File: $mainbase.tex"
914
+ echo " Problem: $error_msg"
915
+ # Don't clean up to let the user diagnose.
916
+ exit 1
917
+ fi
918
+
919
+ if test -n "$output" ; then
920
+ abs_pdffile="$PWD/$pdffile"
921
+ (cd "$initial_dir" && mv "$abs_pdffile" "$output")
922
+ pdffile="$output"
923
+ echo "Output written on $pdffile"
924
+ elif [ -f "$pdffile" ]; then
925
+ new_pdffile="$tmpdir"/"$mainbase".pdf
926
+ mv "$pdffile" "$new_pdffile"
927
+ pdffile="$new_pdffile"
928
+ fi
929
+
930
+ # Change directory so nothing will keep us from cleaning
931
+ cd "$initial_dir"
932
+
933
+ if test "$view" = 1 || ( test "$view" = maybe && test -z "$output" ) ; then
934
+ "$PDFVIEWER" "$pdffile"
935
+ fi
936
+
937
+ case "$cleanup" in
938
+ "all")
939
+ verbose "Cleaning-up result"
940
+ rm -fr "$tmpdir"
941
+ verbose_done
942
+ ;;
943
+ "keeppdf")
944
+ verbose "Cleaning-up all but pdf (kept in $pdffile)"
945
+ rm -fr "$tmpdir"/old "$tmpdir"/new
946
+ verbose_done
947
+ ;;
948
+ "none")
949
+ verbose_say "Generated files kept in $tmpdir/"
950
+ ;;
951
+ esac
packages.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ texlive
2
+ texlive-full
3
+ latexdiff
4
+ biber
5
+ texlive-fonts-extra
6
+ texlive-fonts-recommended
7
+ texlive-bibtex-extra
8
+ texlive-lang-english
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ GitPython
2
+ gradio