Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Download an arXiv article source and recompile the latex as an a5 for
- # reading on a smaller device such as an e-reader or tablet
- # download the source in a temporary folder
- wd="$(pwd)"
- tmpdir="/tmp/arxiv-a5/$1"
- mkdir -p "$tmpdir"
- cd "$tmpdir"
- url=https://arxiv.org/e-print/"$1"
- wget -q -O "$1".tar.gz --user-agent arxiv-a5 "$url"
- tar zxf "$1".tar.gz
- # guess the main tex file
- texfile=$(grep -l '\\begin{document}' *.tex)
- # exit if main tex file not found
- [ -z "$texfile" ] && echo "arXiv paper or main tex file not found in $tmpdir" && exit 1
- # remove existing geometry options, if any
- sed -i '/^\\usepackage.*{geometry}/d' "$texfile"
- # insert the a5 paper size override
- sed -i '/^\\begin{document}/i \\\usepackage[a5paper, margin=1cm]{geometry}\n' "$texfile"
- # compile (twice to get references)
- pdflatex --halt-on-error -draftmode -interaction batchmode "$texfile" > "$1".pdflatex.log
- pdflatex --halt-on-error -interaction batchmode "$texfile" >> "$1".pdflatex.log || echo "Could not compile latex"
- # move the result and tidy up
- mv "$(basename $texfile .tex)".pdf "$wd"/"$1".pdf
- cd "$wd"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement