Run scripts

From Wiki
Jump to navigation Jump to search

While ConTeXt (i.e. mtxrun) already automates a lot, in bigger projects I find it tedious to call context with all its options all the time. One might use make or arara, but I mostly use shell scripts (on OSX and Linux). Here are some useful snippets:

#!/bin/bash

OS=`uname`
if [ "$TEXROOT" == "" ]; then
	# setup ConTeXt’s path; I used different locations on OSX and Linux
	# You might also check on the hostname or if the path exists
	if [ "$OS" == "Linux" ]; then
		source /var/opt/context/tex/setuptex /var/opt/context/tex
	elif [ "$OS" == "Darwin" ]; then
		source ~/Library/texmf/tex/setuptex ~/Library/texmf/tex
	fi
fi

# ulimit was 256 on older OSX versions, that's too low for bigger books
if [ `ulimit` != "unlimited" ]; then
	ulimit -S -n 2048
fi

# I like to have my PDFs versioned at least by date
ISODATE=`date +"%Y-%m-%d"`

PRD=$1
if [ "$1" == "" ]; then
	echo Which product?
	ls -Alh prd_*.tex
	exit 1
fi
RESULT=${PRD}_${ISODATE}

MODE=$2
if [ "$MODE" == "" ]; then
	echo Using lowres pictures for preview. Use 'print' parameter for highres mode.
	MOD=lowres
else
	# print
	RESULT=${RESULT}_$MODE
fi

if [ "$OS" == "Darwin" ]; then
	OPEN='open -a Preview'
	SHARE=~/Box
else
	OPEN="qpdfview --quiet"
	SHARE=~/Dropbox
fi

context --jit prd_${PRD} --result=_pdf/$RESULT --mode=$MOD
if [ "$?" == "0" ]; then
	${OPEN} _pdf/$RESULT.pdf &
	cp _pdf/${RESULT}.pdf ${SHARE}/projects/
fi