Skip to content

Commit

Permalink
Latexdiff wrapping script
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Jan 3, 2018
1 parent 00dba4d commit b2eebae
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 6 deletions.
9 changes: 3 additions & 6 deletions .circleci/config.yml
Expand Up @@ -18,11 +18,8 @@ jobs:
name: Copy deploy script to workspace
command: cp ./deploy.sh /tmp/workspace/deploy.sh
- run:
name: Get latexdiff
command: git clone https://github.com/ftilmann/latexdiff && echo | cpan && cpan Algorithm::Diff && ./latexdiff/latexdiff-vc --git -r master main.tex
- run:
name: Build whitepaper diff
command: pdflatex main-diffmaster.tex && bibtex main-diffmaster && pdflatex main-diffmaster.tex && pdflatex main-diffmaster.tex
name: Run latexdiff
command: bash ./latexdiff-wrapper.sh main.tex master
- persist_to_workspace:
root: /tmp/workspace
paths:
Expand All @@ -32,7 +29,7 @@ jobs:
path: ./main.pdf
destination: whitepaper.pdf
- store_artifacts:
path: ./main-diffmaster.pdf
path: ./diff/main.pdf
destination: whitepaper-diff.pdf

deploy-job:
Expand Down
91 changes: 91 additions & 0 deletions latexdiff-wrapper.sh
@@ -0,0 +1,91 @@
#!/bin/sh
# This script was made because latexdiff-vc was acting up
# and not handling bibliographies satisfactorily.
# Taken from https://github.com/ftilmann/latexdiff/pull/127

help () {
echo "Usage: $0 [-d|--dir <dir>]" \
"<file>[.tex] [<old_commit> [<new_commit>]]"
}

# default options
dest="diff"
file=""
a="HEAD"
b=""

# parse options
while [ $# -gt 0 ]; do
case "$1" in
-d|--dir) dest="$2"; shift 2 ;;
-h|-\?|--help) help; exit 0 ;;
--) shift; break ;;
-*) echo "Unknown option $1" >&2; help>&2; exit 1 ;;
*) break;;
esac
done

if [ $# -lt 1 -o $# -gt 3 ]; then
echo "Wrong number of arguments" >&2; help>&2; exit 1
fi

[ $# -ge 1 ] && file="$1"
[ $# -ge 2 ] && a="$2"
[ $# -ge 3 ] && b="$3"

# fetch paths
temp="$(mktemp -d)"
proj="$(git rev-parse --show-toplevel)"
path="$(git rev-parse --show-prefix)"

# sanitize values
temp="$(realpath "$temp")"
proj="$(realpath "$proj")"
dest="$(realpath "$dest")"
file="${file%.tex}"

# clone repositories
cd "$proj"

mkdir -p "$temp/a"
if [ -n "$a" ]; then
git archive --format=tar "$a" | tar xf - -C "$temp/a"
else
git ls-files -z | xargs -0 tar cf - | tar xf - -C "$temp/a"
fi

mkdir -p "$temp/b"
if [ -n "$b" ]; then
git archive --format=tar "$b" | tar xf - -C "$temp/b"
else
git ls-files -z | xargs -0 tar cf - | tar xf - -C "$temp/b"
fi

# generate .bbl (optional?)
if true; then
cd "$temp/a/$path"
pdflatex "$file" -draftmode
bibtex "$file"

cd "$temp/b/$path"
pdflatex "$file" -draftmode
bibtex "$file"
fi

# run latexdiff
mkdir -p "$dest"
latexdiff --flatten "$temp/a/$path/$file.tex" "$temp/b/$path/$file.tex" \
> "$dest/$file.tex"

# combine all old files and new files (added/removed figures, etc)
cp -anT "$temp/a" "$temp/b"

# compile LaTeX, with access to other files
cd "$temp/b/$path"
pdflatex -output-directory="$dest" "$dest/$file" -draftmode # 1
pdflatex -output-directory="$dest" "$dest/$file" -draftmode # 2 (line numbers)
pdflatex -output-directory="$dest" "$dest/$file" # 3

# cleanup
rm -Rf "$temp"

0 comments on commit b2eebae

Please sign in to comment.