#!/bin/bash if [ -z $1 ] then echo "Usage: $0 number [version] number: number of sheet, 0 for combined document version: 1 for problems, 2 for solutions $0 filename filename: target file to be compiled" exit 1 fi num="$1" ver="$2" main="exfserm" source="exfser" target1="Problems" target2="Solutions" sheets="01 02 03 aa" nl=$'\n' sheetokay="" make=".pdf" for v in $target1 $target2 do if [[ $num =~ ^$v ]] then ver=$v num=${num#$v} if [[ $num =~ ^.*\.tex$ ]]; then make=".tex"; fi num=${num%%.*} fi done if [[ $num =~ ^[0-9]$ ]]; then num="0$num"; fi if [[ $num == "00" ]]; then num=""; fi if [[ -z $num ]]; then sheetokay="okay"; fi for v in $sheets do if [[ "$num" == "$v" ]]; then sheetokay="okay"; fi done if [[ -z $sheetokay ]] then echo "error: unknown sheet" exit 1 fi function docompile { if [[ -z $num ]]; then job=$main; else job=$source$num; fi for par in -draftmode "" do body="\\def\\jobname{$job}\\def\\draftver{n}\\def\\printsol{$sol}" body="$body\\input{childdoc.def}" if [[ -z $num ]] then body="$body\\childdocforward{$main}" else body="$body\\childdocforward[$main]{$source$num}" fi drop="This is|entering extended mode|\\write18" drop="$drop|Preloading the plain mem file|mpost\.mp|plain\.mp" pdflatex -shell-escape -interaction=batchmode $par \ -jobname "$target$num" "$body" | grep -vE "$drop" done grep -E "Warning|Error|Undefined|Overfull|Underfull" "$target$num.log" } function writesource { body="\\def\\draftver{n}$nl\\def\\printsol{$sol}$nl" body="$body\\input{childdoc.def}$nl" if [[ -z $num ]] then body="$body\\childdocforward{$main}" else body="$body\\childdocforwardprefix[$main]{$target}{$source}" fi echo "$body" > $target$num.tex } function process { target=$1 sol=$2 if [[ "$make" == ".pdf" ]]; then docompile; else writesource; fi } if [[ -z $ver || "$ver" == "$target1" || $ver = 1 ]] then process $target1 n fi if [[ -z $ver || "$ver" == "$target2" || $ver = 2 ]] then process $target2 y fi echo