-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_tutorials_tex.sh
More file actions
executable file
·131 lines (108 loc) · 3.29 KB
/
build_tutorials_tex.sh
File metadata and controls
executable file
·131 lines (108 loc) · 3.29 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
#!/usr/bin/env bash
set -euo pipefail
# Toggle arXiv build (default: false)
BUILD_ARXIV=${1:-false}
# ------------------------------------------------------------
# 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"
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"
mkdir -p "$MD_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
# ------------------------------------------------------------
echo "==> Cleaning figure captions"
for f in "$MD_DIR"/*.md; do
sed -i '' 's/!\[png\]/![]/g' "$f"
done
# ------------------------------------------------------------
# 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 \
-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 \
-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"