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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#! /bin/sh
# Bourne shell script to process the Beginner's LaTeX document
# GNU Copyleft 2002, 2003 Silmaril Consultants (info@silmaril.ie)
# This should probably be rewritten as a Makefile one day
# Dependencies: cat, sed, saxon, java, awk, latex, bibtex,
# makeindex, dvips, gs, gzip, xdvi, mv, bash
echo WARNING: you must use Saxon 8 for this because earlier versions
echo fail to handle nested parameter entity references correctly.
####################################################################
# 1. Generate LaTeX source, switching any governing target to latex
# Omit tugbook format now that it's been published
for s in typebook; do
sed -e "s+target \"html\"+target \"latex\"+" beginlatex.xml >beginlatex.XML
saxon beginlatex.XML $s-latex.xslt beginlatex-$s.tex style=$s
# 2. Process the LaTeX to DVI, iterating to resolve cross-references
latex \\nonstopmode\\input beginlatex-$s.tex
bibtex beginlatex-$s
cp beginlatex-$s.bbl beginlatex.bbl
latex \\nonstopmode\\input beginlatex-$s.tex
latex \\nonstopmode\\input beginlatex-$s.tex
makeindex -s indexhead.ist beginlatex-$s
latex \\nonstopmode\\input beginlatex-$s.tex
# pdflatex \\nonstopmode\\input beginlatex-$s.tex
mv beginlatex-$s.pdf beginlatex-$s-pdflatex.pdf
if [ "$1" = "short" ]; then exit; fi
# 3. Generate PostScript and PDF
rm -f beginlatex-$s.ps.gz
if [ "$s" = "tugbook" ]; then
dvips -t letter -o beginlatex-$s.ps beginlatex-$s
gs -sDEVICE=pdfwrite -sPAPERSIZE=letter \
-sOutputFile=beginlatex-$s-psdvips.pdf -q - <beginlatex-$s.ps
else
dvips -t a4 -o beginlatex-$s.ps beginlatex-$s
gs -sDEVICE=pdfwrite -sPAPERSIZE=a4 \
-sOutputFile=beginlatex-$s-psdvips.pdf -q - <beginlatex-$s.ps
fi
gzip beginlatex-$s.ps
# 4. Pop up the preview if it's not already there
XDVI=`ps axu | grep xdvi | grep -v grep`
if [ -z "$XDVI" ]; then
xdvi beginlatex-$s &
fi
done
if [ "$1" = "medium" ]; then exit; fi
# 5. Do the single-file HTML
sed -e "s+target \"latex\"+target \"html\"+" beginlatex.xml >beginlatex.XML
saxon beginlatex.XML typebook-html.xslt beginlatex.html
# 8. Do the multi-file HTML by passing the ID value of the prelims,
# the chapters, the appendices, the bibliography, and the index
# through to Saxon, where the XSLT stylesheet uses them to output
# just that section.
for id in `nsgmls -wxml -E 5000 -f/dev/null \
/usr/local/lib/sgml/xml/xml.dcl beginlatex.xml|\
grep -iE '^(Aid|\(chapter|\(appendix|\(preface|\(index$|\(bibliography)'|\
grep -v IMPLIED|\
awk 'BEGIN {z[1]="A";z[2]="B";z[3]="C"} \
/Aid/ {id=$3} \
{name=substr($1,2)} \
{if($1~"preface"){name=id}} \
{if($1~"chapter"){++c;name="chapter" c}} \
{if($1~"appendix"){++a;name="appendix" z[a]}} \
/\(/ {print name "," id}'`; do
FRAG=`echo $id|awk -F, '{print $1}'`
ID=`echo $id|awk -F, '{print $2}'`
echo $FRAG \($ID\)
if [ "$FRAG" = "preface" ]; then
FRAG=$ID
fi
saxon beginlatex.XML typebook-html.xslt $FRAG.html fragment=$ID
done
# 9. Move the output to the parent directory and HTML directory
echo Moving output files to the right place...
mv -f beginlatex*.ps.gz ..
mv -f beginlatex*.pdf ..
mv -f *.html ../html
cp -f *.png ../html
exit 0
|