Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/recipe-fiddle.git
#!/bin/bash

source /home/context/bin/context/tex/setuptex

OSFONTDIR=/usr/local/share/fonts:/usr/share/fonts/type1/gsfonts
INCLUDE_PATH=/home/context/
OPTIONS="--purgeresult --purgeall --paranoid --batchmode --noconsole --path=$INCLUDE_PATH --directives=schemes.threshold=120"

context $OPTIONS $1

BOOK_PATH=$(dirname $1)
BOOK_FILE=$(basename $1 .tex)
BOOK_NAME=$BOOK_PATH/$BOOK_FILE

# @see http://tex.stackexchange.com/a/41273/2148
# screen   (screen-view-only quality, 72 dpi images)
# ebook    (low quality, 150 dpi images)
# printer  (high quality, 300 dpi images)
# prepress (high quality, color preserving, 300 dpi imgs)
# default  (almost identical to /screen)
BOOK_RESOLUTION=ebook

# Compress the file to reduce bandwidth.
# -sDEVICE = PDF output
# -dCompatibilityLevel = Version 1.4 of PDF specification
# -dNOPAUSE -dQUIET -dBATCH = Non-interactive execution
# -dAutoRotatePages = Prevent GhostScript from trying to rotate pages
# -dPDFSETTINGS = Output quality (see above)
# -dUseCIEColor = Prevent core dump from bad PNGs (invalid colour model?)
# -sOutputFile = Destination file
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH \
   -dAutoRotatePages=/None \
   -dPDFSETTINGS=/$BOOK_RESOLUTION \
   -dUseCIEColor \
   -sOutputFile=$BOOK_NAME-$BOOK_RESOLUTION.pdf $BOOK_NAME.pdf

# Transmit the GhostScript post-processed version of the file
mv -f $BOOK_NAME-$BOOK_RESOLUTION.pdf $BOOK_NAME.pdf