-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnewChapter.sh
More file actions
executable file
·94 lines (69 loc) · 2.56 KB
/
Copy pathnewChapter.sh
File metadata and controls
executable file
·94 lines (69 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
#!/bin/sh
OPTIND=1
help() {
echo "$0 -l LectureName -c ChapterName -n ChapterNumber -r LabelForReferencing -v"
exit 1;
}
debug() {
echo "Lecture: " ${lecture}
echo "Chapter Name: " ${chapterName}
echo "Chapter Label: " ${chapterLabel}
echo "Chapter Number: " ${chapterNumber}
echo "Counter value: " ${counterValue}
}
# variables we want:
lecture="Computer Networks"
chapterName="Organisation"
chapterLabel="org"
chapterNumber=0
verbose=0
while getopts "hvl:c:n:r:d" opt ; do
case "${opt}" in
l) lecture=${OPTARG}
;;
c) chapterName=${OPTARG}
;;
n) chapterNumber=${OPTARG}
;;
r) chapterLabel=${OPTARG}
;;
h) help
;;
v) verbose=1
;;
*) help
;;
esac
done
counterValue=$(expr $chapterNumber - 1)
if [[ $verbose -ne 0 ]]
then
debug
fi
echo "Creating new chapter"
# create new directory
[[ -d ch_${chapterLabel} ]] && { echo "Directory already exists, aborting." ; exit -1 ; }
mkdir ch_${chapterLabel}
# non-template content
pushd ch_${chapterLabel} ; ln -s ../Makefile ; popd
mkdir ch_${chapterLabel}/figures
mkdir ch_${chapterLabel}/standalone
# org files from template
sed s/DDD/${chapterLabel}/ < templates/ch_empty/ch_empty_content.org > ch_${chapterLabel}/ch_${chapterLabel}_content.org
sed s/AAA/"${lecture}"/ < templates/ch_empty/ch_empty.org | \
sed s/BBB/"${chapterName}"/ | \
sed s/CCC/"ch_${chapterLabel}"/ | \
sed s/DDD/"${counterValue}"/ \
> ch_${chapterLabel}/ch_${chapterLabel}.org
# link pseudo tex files to tex file, just to have the names in place
# pushd ch_${chapterLabel} ; ln -s ch_${chapterLabel}.tex ch_${chapterLabel}_169.tex ; popd
pushd ch_${chapterLabel} ; ln -s ch_${chapterLabel}.tex ch_${chapterLabel}_handout.tex ; popd
pushd ch_${chapterLabel}/standalone ; ln -s ../../Makefile_standalone_figures Makefile ; popd
# put an external document reference into templates
echo "#+LATEX_HEADER: \externaldocument{../ch_${chapterLabel}/ch_${chapterLabel}}" >> templates/externaldocuments.org
# modify book: create an entry to include that chapter, just before the appendix
sed -I~ "s/* Appendix/** ${chapterName}\n\n#+include: \"..\/ch_${chapterLabel}\/ch_${chapterLabel}_content.org\"\n\n\n* Appendix/" book/book.org
# and make sure that the graphicspaths in book point to all relevant subdirectories
echo "\\\\appendtographicspath{{../ch_${chapterLabel}/}}" >> book/graphicspath.tex
echo "\\\\appendtographicspath{{../ch_${chapterLabel}/standalone/}}" >> book/graphicspath.tex
echo "\\\\appendtographicspath{{../ch_${chapterLabel}/figures/}}" >> book/graphicspath.tex