#!/bin/ksh93
##
##  pdfjam-slides3up: A shell program to make a 3-up "handout" 
##  of presentation slides, with space for side-notes
##
##  Author David Firth (http://go.warwick.ac.uk/dfirth)
##
##  This is a simple wrapper for pdfjam, version 2.08
##
typeset -r FPROG=${.sh.file}
typeset -r PROG=${FPROG##*/}
typeset -r SDIR=${FPROG%/*}

set -A OPTS
if [[ ${PROG} == 'pdfjam-slides3up' ]]; then
	OPTS=(
		'-O' 'footskip=3.1cm'	'-O' 'nup=1x3'	'-O' 'delta="0cm 0.2cm"'
		'-O' 'scale=0.87'						'-O' 'offset="-3.8cm 0cm"'
	)
else	# 6up
	OPTS=(
		'-O' 'footskip=2.7cm'	'-O' 'nup=2x3'	'-O' 'delta="0.2cm 0.3cm"'
		'-O' 'scale=0.95'
	)
fi

pagecommand='{\thispagestyle{empty}}'    ## default setting
if [[ $1 == '--pagenumbering' ]]; then
	if [[ $2 == 'false' ]]; then
		:
	elif [[ $2 == 'true' ]]; then
		pagecommand='{\thispagestyle{plain}}'
	else
		## a footskip dimension was supplied
		pagecommand='{\thispagestyle{plain}}'
		footskip="$2"
	fi ;
	shift 2
fi
exec pdfjam --suffix=${PROG:12} \
	-O 'frame=true' -O 'noautoscale=false' "${OPTS[@]}" \
	--preamble "\\footskip ${footskip}" -O "pagecommand='${pagecommand}'" "$@"
