forked from cvmfs/doc-cvmfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatex2rst.sh
executable file
·68 lines (51 loc) · 1.73 KB
/
latex2rst.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
#!/bin/bash
set -e
SCRIPT_LOCATION=$(cd "$(dirname "$0")"; pwd)
die() {
echo "$1" >&2
exit 1
}
has() {
which $1 > /dev/null 2>&1
}
has pandoc || die "pandoc needs to be installed"
has pandoc-citeproc || die "pandoc-citeproc needs to be installed"
if [ $# -ne 2 ]; then
echo "Usage: $0 <LaTeX source file> <RST destination directory>"
exit 2
fi
SRC_FILE="$1"
DST_DIR="$2"
SRC_DIR=$(dirname $SRC_FILE)
[ -e $SRC_FILE ] || die "$SRC_FILE doesn't exist"
[ -d $DST_DIR ] || die "$DST_DIR doesn't exist"
INDEXDOC="cvmfstech.tex"
BIBLIOGRAHPY="references.bib"
CSL="${SCRIPT_LOCATION}/acm-sig-proceedings.csl"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo -n "setting up environment... "
cleanup() {
rm -f $PREAMBLE
rm -f $FILTERED_SRC
}
trap cleanup EXIT HUP INT TERM
PREAMBLE=$(mktemp)
FILTERED_SRC=$(mktemp)
echo "done"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
echo -n "preparing preamble... "
grep -e 'providecommand' ${SRC_DIR}/${INDEXDOC} > $PREAMBLE
echo "\renewcommand{\product}[1]{#1}" >> $PREAMBLE
echo "\renewcommand{\indexed}[1]{#1}" >> $PREAMBLE
echo "done"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
dst="$(basename -s .tex $SRC_FILE).rst"
echo -n "converting ${SRC_FILE} to ${dst}... "
cat ${SRC_FILE} | sed -e 's/\\SI{\([0-9]*\)}{\\bit}/\1 bit/g' > $FILTERED_SRC
pandoc --from latex \
--to rst \
--bibliography=${SRC_DIR}/${BIBLIOGRAHPY} \
--csl=$CSL \
$PREAMBLE \
${FILTERED_SRC} > ${DST_DIR}/$dst || die "fail"
echo "done"