-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_tutorials_tex2.sh
More file actions
executable file
·169 lines (137 loc) · 4.32 KB
/
build_tutorials_tex2.sh
File metadata and controls
executable file
·169 lines (137 loc) · 4.32 KB
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
#!/usr/bin/env bash
set -euo pipefail
# Toggle arXiv build (default: false)
BUILD_ARXIV=$(echo "${1:-false}" | tr '[:upper:]' '[:lower:]')
# ------------------------------------------------------------
# Build a single LaTeX file from BoolForge tutorial notebooks
# ------------------------------------------------------------
TUTORIAL_DIR="tutorials"
MD_DIR="tutorials_md"
OUT_TEX="BoolForge_Tutorials.tex"
HEADER_TEX="tutorials_header.tex"
FIG_DIR="figures"
TITLE="Boolean Network Modeling in Systems Biology: A Hands-On Tutorial with BoolForge"
AUTHOR="Claus Kadelka"
echo "==> Cleaning previous build artifacts"
rm -rf "$MD_DIR" "$OUT_TEX" "$HEADER_TEX" "$FIG_DIR"
mkdir -p "$MD_DIR" "$FIG_DIR"
# ------------------------------------------------------------
# Convert notebooks to Markdown
# ------------------------------------------------------------
echo "==> Converting notebooks to Markdown"
for nb in "$TUTORIAL_DIR"/*.ipynb; do
jupyter nbconvert \
--to markdown \
--TemplateExporter.exclude_input_prompt=True \
--TemplateExporter.exclude_output_prompt=True \
"$nb" \
--output-dir "$MD_DIR"
done
# ------------------------------------------------------------
# Remove "png" captions (portable sed)
# ------------------------------------------------------------
echo "==> Cleaning figure captions"
for f in "$MD_DIR"/*.md; do
sed -i.bak 's/!\[png\]/![]/g' "$f"
rm "$f.bak"
done
# ------------------------------------------------------------
# Flatten figure directories into figures/
# ------------------------------------------------------------
echo "==> Flattening figure directories"
for md in "$MD_DIR"/*.md; do
base=$(basename "$md" .md)
files_dir="$MD_DIR/${base}_files"
if [ -d "$files_dir" ]; then
counter=0
for img in "$files_dir"/*; do
ext="${img##*.}"
new_name="${base}_fig${counter}.${ext}"
cp "$img" "$FIG_DIR/$new_name"
# portable sed replace
sed -i.bak "s|${base}_files/$(basename "$img")|${FIG_DIR}/${new_name}|g" "$md"
rm "$md.bak"
((counter++))
done
fi
done
# remove original _files folders
rm -rf "$MD_DIR"/*_files
# ------------------------------------------------------------
# Create LaTeX header (arXiv-safe)
# ------------------------------------------------------------
echo "==> Writing LaTeX header"
cat > "$HEADER_TEX" <<'EOF'
\usepackage{graphicx}
\usepackage{float}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{caption}
\usepackage{listings}
\usepackage{hyperref}
% allow alt= in includegraphics
\makeatletter
\define@key{Gin}{alt}{}
\makeatother
% prevent oversized figures
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\makeatother
\setkeys{Gin}{width=\maxwidth,height=0.8\textheight,keepaspectratio}
% code formatting
\lstset{
basicstyle=\ttfamily\small,
breaklines=true,
frame=single
}
% new page per tutorial
\usepackage{etoolbox}
\pretocmd{\section}{\clearpage}{}{}
% nicer captions
\captionsetup{
font=small,
labelfont=bf
}
EOF
# ------------------------------------------------------------
# Build LaTeX
# ------------------------------------------------------------
if [ "$BUILD_ARXIV" = true ]; then
echo "==> Building arXiv version with abstract + intro"
cat arxiv_frontmatter.md "$MD_DIR"/*.md > "$MD_DIR/_combined.md"
pandoc \
"$MD_DIR/_combined.md" \
--resource-path="$MD_DIR" \
--from markdown-yaml_metadata_block+tex_math_dollars \
--standalone \
--toc \
--number-sections \
--listings \
--syntax-highlighting=none \
-M title="$TITLE" \
-M author="$AUTHOR" \
-M date="$(date '+%B %d, %Y')" \
-V geometry:margin=1in \
-V documentclass=article \
-H "$HEADER_TEX" \
-o "$OUT_TEX"
else
echo "==> Building supplement version (no abstract)"
pandoc \
"$MD_DIR"/*.md \
--resource-path="$MD_DIR" \
--from markdown-yaml_metadata_block+tex_math_dollars \
--standalone \
--toc \
--number-sections \
--listings \
--syntax-highlighting=none \
-M title="$TITLE" \
-M author="$AUTHOR" \
-M date="$(date '+%B %d, %Y')" \
-V geometry:margin=1in \
-V documentclass=article \
-H "$HEADER_TEX" \
-o "$OUT_TEX"
fi
echo "==> Done: $OUT_TEX"