blob: 1003fa32522d59c35a252ba34565284b76bb49a2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/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
|