-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_materials
More file actions
executable file
·110 lines (94 loc) · 2.56 KB
/
make_materials
File metadata and controls
executable file
·110 lines (94 loc) · 2.56 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
#!/bin/bash
function ensure_md_trailing_newline ()
{
# Ensure every md file has 2 trailing newlines
for f in $(fd -e md -d 1) ; do
lastline=$(tail -n 1 $f; echo x); lastline=${lastline%x}
if [ "${lastline: -1}" != $'\n' ]; then
echo "styling: $f"
echo >> $f
echo >> $f
fi
done
}
function indent_c_cpp_files_recursively ()
{
# Indent C files and remove temp files
for f in $(fd -e c -e cpp -e h -e hpp); do
echo "indenting: $f"
clang-format --style="{BasedOnStyle: llvm, IndentWidth: 4}" -i $f
rm -f "$f~"
done
}
set -e;
readme="README.md"
materials="MATERIALS.md"
installing="INSTALLING.md"
rm $materials $installing
touch $materials $installing
materials_path=$(realpath "$materials")
installing_path=$(realpath "$installing")
function collect_materials ()
{
if [ ! -f .mignore ] && [ ! -f .mroot ]; then
ensure_md_trailing_newline
fi
if [ -f $readme ]; then
echo "including: $(realpath $readme)"
cat $readme >> $materials_path
fi
if [ -f $installing ]; then
echo "including: $(realpath $installing)"
if [ $(realpath $installing) != $installing_path ]; then
cat $installing >> $installing_path
fi
fi
if [ ! -f .mignore ]; then
for d in *; do
if [ -d $d ]; then
echo "scanning $d..."
cd $d
collect_materials
cd ..
fi
done
fi
}
indent_c_cpp_files_recursively
echo >> $installing_path
echo >> $installing_path
echo "# Instalacije" >> $installing_path
collect_materials
cat $installing_path >> $materials_path
set +e;
echo
echo "creating pdf..."
pandoc MATERIALS.md \
-o MATERIALS.pdf \
--verbose \
-f gfm \
-N \
--variable "geometry=margin=1.2in" \
--variable fontsize=12pt \
--variable version=2.0 \
--pdf-engine=xelatex \
--include-in-header _pandoc/header.tex \
--include-in-header _pandoc/code.tex \
--highlight-style _pandoc/pygments.theme \
-V colorlinks=true \
--toc -V toc-title="Sadržaj" \
-V 'monofont:DejaVuSansMono' \
2>&1 | tee make_materials.log
# Other useful pandoc options
# -V 'mainfont:DejaVuSerif.ttf' \
# -V 'sansfont:DejaVuSans.ttf' \
# -V 'mathfont:texgyredejavu-math.otf' \
exc=$?
echo
echo
if [ $exc -eq 0 ]; then
echo "SUCCESS"
else
echo "ERROR code $exc"
fi
echo "NOTE: if you see verbatim errors, make sure to have qualified codeblocks with language, e.g., \`\`\`txt instead of just \'\'\'"