Advertisement
Guest User

arxiv -> a5paper

a guest
Sep 3rd, 2023
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | Source Code | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Download an arXiv article source and recompile the latex as an a5 for
  4. # reading on a smaller device such as an e-reader or tablet
  5.  
  6. # download the source in a temporary folder
  7. wd="$(pwd)"
  8. tmpdir="/tmp/arxiv-a5/$1"
  9. mkdir -p "$tmpdir"
  10. cd "$tmpdir"
  11. url=https://arxiv.org/e-print/"$1"
  12. wget -q -O "$1".tar.gz --user-agent arxiv-a5 "$url"
  13. tar zxf "$1".tar.gz
  14.  
  15. # guess the main tex file
  16. texfile=$(grep -l '\\begin{document}' *.tex)
  17.  
  18. # exit if main tex file not found
  19. [ -z "$texfile" ] && echo "arXiv paper or main tex file not found in $tmpdir" && exit 1
  20.  
  21. # remove existing geometry options, if any
  22. sed -i '/^\\usepackage.*{geometry}/d' "$texfile"
  23. # insert the a5 paper size override
  24. sed -i '/^\\begin{document}/i \\\usepackage[a5paper, margin=1cm]{geometry}\n' "$texfile"
  25.  
  26. # compile (twice to get references)
  27. pdflatex --halt-on-error -draftmode -interaction batchmode "$texfile" > "$1".pdflatex.log
  28. pdflatex --halt-on-error -interaction batchmode "$texfile" >> "$1".pdflatex.log || echo "Could not compile latex"
  29.  
  30. # move the result and tidy up
  31. mv "$(basename $texfile .tex)".pdf "$wd"/"$1".pdf
  32. cd "$wd"
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement