forked from y-yu/trpl-2nd-pdf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·69 lines (58 loc) · 1.81 KB
/
setup.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
#!/bin/bash
set -ex
# Clone Markdown source
if [[ -d "./book-ja" ]]; then
cd book-ja
git restore book.toml
git checkout master-ja
git pull origin master-ja
else
git clone https://github.com/rust-lang-ja/book-ja
cd book-ja
git fetch
git checkout master-ja
fi
# Build completely markdown files
echo $'\n[output.markdown]' >> book.toml
cat book.toml
/root/.cargo/bin/mdbook build
# Back to the root directory
cd ..
# Download online images
cp -r ./book-ja/src/img ./
mv ./img/ferris/* ./img
for f in ./img/*.svg
do
if [[ $f =~ \./img/(.*)\.svg ]]; then
SVG=`pwd`/img/${BASH_REMATCH[1]}.svg
PDF=`pwd`/${BASH_REMATCH[1]}.pdf
PDFTEX=`pwd`/${BASH_REMATCH[1]}.pdf_tex
inkscape -D "$SVG" --export-filename="$PDF" --export-latex
PAGES=$(egrep -a '/Type /Page\b' "$PDF" | wc -l | tr -d ' ')
python3 ./python/fix_pdf_tex.py "$PAGES" < "$PDFTEX" > "$PDFTEX.tmp"
mv "$PDFTEX.tmp" "$PDFTEX"
fi
done
# Make working directory
if [[ ! -d "./target" ]]; then
mkdir target
fi
# Copy markdown files to the working directory
for f in ./book-ja/book/markdown/*.md; do
cp "$f" target/
done
cp ./book-ja/src/SUMMARY.md target
python3 python/fix_table.py < target/appendix-02-operators.md > target/tmp.md
mv target/tmp.md target/appendix-02-operators.md
for f in target/*.md; do
BASE=$(basename $f .md)
FILTERS="--filter ./python/filter.py"
if [[ $BASE =~ appendix-02- ]]; then
COLUMNS="--columns=10"
fi
FILENAME="$BASE" pandoc -o "./target/$BASE.tex" -f markdown_github+footnotes+header_attributes-hard_line_breaks \
--pdf-engine=lualatex --top-level-division=chapter $COLUMNS --listings $FILTERS $f
done
python3 ./python/body.py < ./target/SUMMARY.md > body.tex
python3 ./python/fix_incsvg.py < target/ch00-00-introduction.tex > target/tmp.tex
mv target/tmp.tex target/ch00-00-introduction.tex