-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit.sh
executable file
·72 lines (55 loc) · 2.01 KB
/
split.sh
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
#!/bin/bash
CHAPDIR="chapters"
SPLITDIR="splits"
# Split all files
for l in fr en; do
mkdir -p $SPLITDIR/$l
for c in $CHAPDIR/$l/*.tex; do
f=$(basename $c)
num=${f%%_*}
csplit --quiet --prefix $SPLITDIR/$l/${num}_\
--suffix-format=%03d.tex \
--elide-empty-files \
$c /^$/+1 {*}
done
done
# Generate document
for c in $CHAPDIR/fr/*.tex; do
f=$(basename $c)
chnum=${f%%_*}
sfile="$SPLITDIR/${chnum}.tex"
# Make chapter title
enchap=$(sed -e 's@\\chapter\(\[.*\]\)\?{\(.*\)}$@\2@' $SPLITDIR/en/${chnum}_000.tex)
entempchap=$(sed -n 's@\\chapter\[\(.*\)\].*}$@\1@p' $SPLITDIR/en/${chnum}_000.tex)
frchap=$(sed -e 's@\\chapter\(\[.*\]\)\?{\(.*\)}$@\2@' $SPLITDIR/fr/${chnum}_000.tex)
frtempchap=$(sed -n 's@\\chapter\[\(.*\)\].*}$@\1@p' $SPLITDIR/fr/${chnum}_000.tex)
if [[ -z $entempchap ]] && [[ -z $frtempchap ]]; then
echo "\\chapter{$enchap \\\\$frchap}" > $sfile
else
[[ -z $entempchap ]] && entempchap="$enchap"
[[ -z $frtempchap ]] && frtempchap="$frchap"
echo "\\chapter[$entempchap \\\\$frtempchap]{$enchap \\\\$frchap}" > $sfile
fi
echo '\normalfont' >> $sfile
echo '\begin{Parallel}{}{}' >> $sfile
for pfr in $SPLITDIR/fr/${chnum}_*.tex; do
secname=$(basename $pfr .tex)
secnum=${secname##*_}
[[ "x$secnum" = "x000" ]] && continue
# Ignore empty files
grep -q '[a-z]' $pfr || continue
pen=${pfr/fr/en}
# Replace chapter with \Huge, section with \Large
sed -i 's@\\section\*@\\secstyle@' $pfr
# Remove lettrines
sed -i 's@\\lettrine{\(.*\)}{\(.*\)}@\1\2@' $pfr
if [ ! -f "$pen" ]; then
echo "E: Missing file $pen"
exit 1
fi
echo '\ParallelPar' >> $sfile
echo "\ParallelLText{\selectlanguage{english}\input{$pen}}" >> $sfile
echo "\ParallelRText{\selectlanguage{french}\input{$pfr}}" >> $sfile
done
echo '\end{Parallel}' >> $sfile
done