-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmakechapter.sh
More file actions
executable file
·130 lines (104 loc) · 2.43 KB
/
makechapter.sh
File metadata and controls
executable file
·130 lines (104 loc) · 2.43 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
#!/bin/bash
printf " *** knit file, fix latex, and move to *** \n\n"
cd ../labs/$1
## Before we knit we create temporary file
## and add a link to the Rmd markdown after every subsection
## but only if not an exercise file
if [[ ! "$2" =~ "_exercises" ]] && [[ $2 != "introduction" ]]
then
linetoadd="The R markdown document for this section is available \[here]\(https\:\/\/github.com\/genomicsclass\/labs\/tree\/master\/$1\/$2.Rmd\)."
sed '/^## /a \
\'$'\n@@@@@@
' $2.Rmd | sed 's/@@@@@@/'"$linetoadd"'/' > $2-tmp.Rmd
else
cp $2.Rmd $2-tmp.Rmd
fi
## Now we knit
Rscript --no-init-file -e "library(knitr); knit('$2-tmp.Rmd', quiet=TRUE)"
### Here we are converting the $ used by latex to $$ used by jekyll
sed 's/\$\$/@@@@/g' $2-tmp.md |
sed 's/ \$/ @@@@/g' |
sed 's/\$ /@@@@ /g' |
sed 's/\$\./@@@@\./g' |
sed 's/\$,/@@@@,/g' |
sed 's/\$:/@@@@:/g' |
sed 's/\$?/@@@@?/g' |
sed 's/\$-/@@@@-/g' |
sed 's/(\$/(@@@@/g' |
sed 's/\$)/@@@@)/g' |
sed 's/^\$/@@@@/g' |
sed 's/\$$/@@@@/g' |
sed 's/:\$/:@@@@/g' |
sed 's/@@@@/\$\$/g' |
sed 's/\$\$/{\$\$}/g' |
sed 's/(figure\//(images\/R\//g' |
sed 's/\"figure\//\"images\/R\//g'> $2.md
rm $2-tmp.Rmd
rm $2-tmp.md
### Here we are converting the $$ used by latex and jekyll to
### in {$$} {\$$} used by leanpub
awk '
BEGIN {count = 0;}
{
gsub(/\{\$\$\}/,"@@@@\{\$\$\}@@@@");
n=split($0,a,"@@@@")
line = "";
for (i=1;i<=n;++i){
if(a[i]=="\{\$\$\}") {
++count;
if(count==2) {
a[i] = "\{/\$\$\}";
count=0
}
}
line=(line a[i])
}
print line;
}
' $2.md > $2-tmp.md
rm $2.md
### If exercises add the A>
if [[ "$2" =~ "_exercises" ]]
then
awk '
BEGIN {start=0; flag=1}
{
if ($0 ~ "## Exercises") { start = 1 }
if ($0 ~ "```r")
{
flag=0
print $0
}
else
{
if (start && flag) print "A>" $0
else
{
print $0
if ($0 ~ "```") flag=1
}
}
}
' $2-tmp.md > $2.md
rm $2-tmp.md
else
mv $2-tmp.md $2.md
fi
##mv to leanpub and move over the final md
cd ../../leanpub
mv ../labs/$1/$2.md ./manuscript
## move the images into leanpub directory and add to github
imgcount=`ls -1 ../labs/$1/figure/$2* 2> /dev/null | wc -l`
if [ $imgcount -gt 0 ]
then
mv ../labs/$1/figure/$2* manuscript/images/R/
fi
printf " *** add new files to BOOK, commit and push *** \n\n"
cd manuscript
git add $2.md
if [ $imgcount -gt 0 ]
then
git add images/R/$2*
fi
git commit -am "adding $2 to book" > /dev/null
printf "\n *** done! *** \n\n"