forked from csev/py4e
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbook.sh
executable file
·192 lines (131 loc) · 9.08 KB
/
book.sh
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
set -ex
mkdir -p ../translations/PL
# EPUB and MOBI versions
cat epub-metadata.txt <(sed -e "s/^Copyright 2009– /Copyright 2009–$(date +%Y) /" -e "s/^Wydanie \(.*\), 20..$/Wydanie \\1, $(date '+%Y-%m-%d')/" A0-preface.mkd) 0*.mkd 1*.mkd AA*.mkd AB*.mkd | grep -v '^%' | python2 pre-html.py | python2 verbatim.py | pandoc --default-image-extension=svg --css=stylesheet.css -o x.epub
# make the mobi if it works (add verbose for debugging)
if hash ebook-convert 2>/dev/null; then
ebook-convert x.epub x.mobi
echo "mobi generated"
else
echo "mobi not generated - please install calibre"
exit 1
fi
# fixer for ingramspark
bash epub-fixer.sh
mv x.epub ../translations/PL/py4e-pl-latest.epub
mv x.mobi ../translations/PL/py4e-pl-latest.mobi
# cleanup
rm -f tmp-1.* tmp-2.* tmp-3.* tmp-4.* *.tmp *.aux
rm -f ../images/*-eps-converted-to.pdf
rm -f ../photos/*-eps-converted-to.pdf
# PDF print color version
pandoc <(sed -e "s/^Copyright 2009– /Copyright 2009–$(date +%Y) /" -e "s/^Wydanie \(.*\), 20..$/Wydanie \\1, $(date '+%Y-%m-%d')/" A0-preface.mkd) -o tmp-1.prefacex.tex
sed < tmp-1.prefacex.tex 's/section{/section*{/' > tmp-1.preface.tex
cat [0-9]*.mkd | python2 verbatim.py | tee tmp-1.verbatim | pandoc -s -N -f markdown+definition_lists -t latex --toc --default-image-extension=eps -V pdfversionprint -V fontsize:10pt -V documentclass:book -V lang:pl-PL -V langbabel:polish -V "author:Dr Charles R. Severance" -V "title:Python dla wszystkich" -V "subtitle:Odkrywanie danych z Python 3" -V colorlinks:false -V citecolor:black -V urlcolor:black -V linkcolor:black -V numbersections -V printbook -V typeinclude_t1 --syntax-definition=sql.xml --template=template.latex --listings -V listings-disable-line-numbers:true -o tmp-1.tex
pandoc [A-Z][A-Z]*.mkd -o tmp-1.app.tex
sed < tmp-1.app.tex -e 's/subsubsection{/xyzzy{/' -e 's/subsection{/plugh{/' -e 's/section{/chapter{/' -e 's/xyzzy{/subsection{/' -e 's/plugh{/section{/' > tmp-1.appendix.tex
sed < tmp-1.tex '/includegraphics/s/jpg/eps/' | sed 's"includegraphics{../photos"includegraphics[height=3.0in]{../photos"' > tmp-1.sed
diff tmp-1.sed tmp-1.tex
python2 texpatch.py < tmp-1.sed > tmp-1.patch
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-1.preface.tex
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-1.appendix.tex
mv tmp-1.patch tmp-1.tex
perl -0777 -i -pe "s/\\\\href\\{(.+?)\\}\\{(.+?)\\}/\\\\href{\1}{\\\\nolinkurl{\2}}/igs" tmp-1.tex
pdflatex -shell-escape tmp-1.tex # first, TOC
pdflatex -shell-escape tmp-1.tex # second, add TOC
mv tmp-1.pdf x-1.pdf
gs -o x-1-cmyk.pdf \
-sDEVICE=pdfwrite \
-dOverrideICC \
-sProcessColorModel=DeviceCMYK \
-sColorConversionStrategy=CMYK \
-sColorConversionStrategyForImages=CMYK \
-dEmbedAllFonts=true \
x-1.pdf
##pdfjam --outfile x-1.pdf --papersize '{7in,10in}' x-1-cmyk.pdf
mv x-1-cmyk.pdf x-1.pdf
mv x-1.pdf ../translations/PL/py4e-pl-print-latest.pdf
# cleanup
rm -f tmp-1.* tmp-2.* tmp-3.* tmp-4.* *.tmp *.aux
rm -f ../images/*-eps-converted-to.pdf
rm -f ../photos/*-eps-converted-to.pdf
# PDF print A4
pandoc <(sed -e "s/^Copyright 2009– /Copyright 2009–$(date +%Y) /" -e "s/^Wydanie \(.*\), 20..$/Wydanie \\1, $(date '+%Y-%m-%d')/" A0-preface.mkd) -o tmp-2.prefacex.tex
sed < tmp-2.prefacex.tex 's/section{/section*{/' > tmp-2.preface.tex
cp 01-intro.mkd 01-intro.mkd.orig
sed -i "3s/.*/% Ostatnia aktualizacja: $(date '+%Y-%m-%d')/" 01-intro.mkd
cat [0-9]*.mkd | python2 verbatim.py | tee tmp-2.verbatim | pandoc -s -N -f markdown+definition_lists -t latex --toc --default-image-extension=eps -V pdfversiona4 -V fontsize:10pt -V documentclass:book -V papersize:a4paper -V openany -V lang:pl-PL -V langbabel:polish -V "author:Dr Charles R. Severance" -V "title:Python dla wszystkich" -V "subtitle:Odkrywanie danych z Python 3" -V numbersections -V typeinclude_t2 --template=template.latex --syntax-definition=sql.xml --listings -V listings-disable-line-numbers:true -o tmp-2.tex
pandoc [A-Z][A-Z]*.mkd -o tmp-2.app.tex
mv 01-intro.mkd.orig 01-intro.mkd
sed < tmp-2.app.tex -e 's/subsubsection{/xyzzy{/' -e 's/subsection{/plugh{/' -e 's/section{/chapter{/' -e 's/xyzzy{/subsection{/' -e 's/plugh{/section{/' > tmp-2.appendix.tex
sed < tmp-2.tex '/includegraphics/s/jpg/eps/' | sed 's"includegraphics{../photos"includegraphics[height=3.0in]{../photos"' > tmp-2.sed
diff tmp-2.sed tmp-2.tex
python2 texpatch.py < tmp-2.sed > tmp-2.patch
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-2.preface.tex
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-2.appendix.tex
mv tmp-2.patch tmp-2.tex
perl -0777 -i -pe "s/\\\\href\\{(.+?)\\}\\{(.+?)\\}/\\\\href{\1}{\\\\nolinkurl{\2}}/igs" tmp-2.tex
pdflatex -shell-escape tmp-2.tex # first, TOC
pdflatex -shell-escape tmp-2.tex # second, add TOC
mv tmp-2.pdf x-2.pdf
mv x-2.pdf ../translations/PL/py4e-pl-a4-latest.pdf
# cleanup
rm -f tmp-1.* tmp-2.* tmp-3.* tmp-4.* *.tmp *.aux
rm -f ../images/*-eps-converted-to.pdf
rm -f ../photos/*-eps-converted-to.pdf
# PDF print b/w version (disabled color syntax highlighting)
pandoc <(sed -e "s/^Copyright 2009– /Copyright 2009–$(date +%Y) /" -e "s/^Wydanie \(.*\), 20..$/Wydanie \\1, $(date '+%Y-%m-%d')/" A0-preface.mkd) -o tmp-3.prefacex.tex
sed < tmp-3.prefacex.tex 's/section{/section*{/' > tmp-3.preface.tex
cat [0-9]*.mkd | python2 verbatim.py | tee tmp-3.verbatim | pandoc -s -N -f markdown+definition_lists -t latex --toc --default-image-extension=eps -V pdfversionprint -V fontsize:10pt -V documentclass:book -V lang:pl-PL -V langbabel:polish -V "author:Dr Charles R. Severance" -V "title:Python dla wszystkich" -V "subtitle:Odkrywanie danych z Python 3" -V colorlinks:false -V citecolor:black -V urlcolor:black -V linkcolor:black -V numbersections -V printbook --highlight-style=monochrome -V typeinclude_t3 --template=template.latex --listings -V listings-disable-line-numbers:true -V blackandwhite --syntax-definition=sql.xml -o tmp-3.tex
pandoc [A-Z][A-Z]*.mkd -o tmp-3.app.tex
sed < tmp-3.app.tex -e 's/subsubsection{/xyzzy{/' -e 's/subsection{/plugh{/' -e 's/section{/chapter{/' -e 's/xyzzy{/subsection{/' -e 's/plugh{/section{/' > tmp-3.appendix.tex
sed < tmp-3.tex '/includegraphics/s/jpg/eps/' | sed 's"includegraphics{../photos"includegraphics[height=3.0in]{../photos"' > tmp-3.sed
diff tmp-3.sed tmp-3.tex
python2 texpatch.py < tmp-3.sed > tmp-3.patch
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-3.preface.tex
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-3.appendix.tex
mv tmp-3.patch tmp-3.tex
perl -0777 -i -pe "s/\\\\href\\{(.+?)\\}\\{(.+?)\\}/\\\\href{\1}{\\\\nolinkurl{\2}}/igs" tmp-3.tex
pdflatex -shell-escape tmp-3.tex # first, TOC
pdflatex -shell-escape tmp-3.tex # second, add TOC
mv tmp-3.pdf x-3.pdf
gs -o x-3-cmyk.pdf \
-sDEVICE=pdfwrite \
-dOverrideICC \
-sProcessColorModel=DeviceCMYK \
-sColorConversionStrategy=CMYK \
-sColorConversionStrategyForImages=CMYK \
-dEmbedAllFonts=true \
x-3.pdf
##pdfjam --outfile x-3.pdf --papersize '{7in,10in}' x-3-cmyk.pdf
mv x-3-cmyk.pdf x-3.pdf
mv x-3.pdf ../translations/PL/py4e-pl-print-bw-latest.pdf
# cleanup
rm -f tmp-1.* tmp-2.* tmp-3.* tmp-4.* *.tmp *.aux
rm -f ../images/*-eps-converted-to.pdf
rm -f ../photos/*-eps-converted-to.pdf
# PDF electronic A4
pandoc <(sed -e "s/^Copyright 2009– /Copyright 2009–$(date +%Y) /" -e "s/^Wydanie \(.*\), 20..$/Wydanie \\1, $(date '+%Y-%m-%d')/" A0-preface.mkd) -o tmp-4.prefacex.tex
sed < tmp-4.prefacex.tex 's/section{/section*{/' > tmp-4.preface.tex
cp 01-intro.mkd 01-intro.mkd.orig
sed -i "3s/.*/% Ostatnia aktualizacja: $(date '+%Y-%m-%d')/" 01-intro.mkd
cat [0-9]*.mkd | python2 verbatim.py | tee tmp-4.verbatim | pandoc -s -N -f markdown+definition_lists -t latex --toc --default-image-extension=eps -V pdfversiona4 -V fontsize:10pt -V documentclass:book -V papersize:a4paper -V openany -V lang:pl-PL -V langbabel:polish -V "author:Dr Charles R. Severance" -V "title:Python dla wszystkich" -V "subtitle:Odkrywanie danych z Python 3" -V numbersections -V fontcode:lmss -V typeinclude_t4 --template=template.latex --syntax-definition=sql.xml --listings -V listings-disable-line-numbers:true -o tmp-4.tex
pandoc [A-Z][A-Z]*.mkd -o tmp-4.app.tex
mv 01-intro.mkd.orig 01-intro.mkd
sed < tmp-4.app.tex -e 's/subsubsection{/xyzzy{/' -e 's/subsection{/plugh{/' -e 's/section{/chapter{/' -e 's/xyzzy{/subsection{/' -e 's/plugh{/section{/' > tmp-4.appendix.tex
sed < tmp-4.tex '/includegraphics/s/jpg/eps/' | sed 's"includegraphics{../photos"includegraphics[height=3.0in]{../photos"' > tmp-4.sed
diff tmp-4.sed tmp-4.tex
python2 texpatch.py < tmp-4.sed > tmp-4.patch
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-4.preface.tex
perl -0777 -i -pe "s/\`\`(.+?)''/\\\\enquote{\1}/igs" tmp-4.appendix.tex
mv tmp-4.patch tmp-4.tex
perl -0777 -i -pe "s/\\\\href\\{(.+?)\\}\\{(.+?)\\}/\\\\href{\1}{\\\\nolinkurl{\2}}/igs" tmp-4.tex
pdflatex -shell-escape tmp-4.tex # first, TOC
pdflatex -shell-escape tmp-4.tex # second, add TOC
mv tmp-4.pdf x-4.pdf
mv x-4.pdf ../translations/PL/py4e-pl-a4-online-latest.pdf
# cleanup
rm -f tmp-1.* tmp-2.* tmp-3.* tmp-4.* *.tmp *.aux
rm -f ../images/*-eps-converted-to.pdf
rm -f ../photos/*-eps-converted-to.pdf