aboutsummaryrefslogtreecommitdiff
path: root/websvgtex
blob: 76ab13936904e83a24dc98c6eda131b0ed28bba1 (plain) (blame)
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
#!/bin/sh

err() {
	{ set +x; } 2>/dev/null
	echo "$@" >&2
	exit 1
}

ensure_noset() {  
        [ $# -lt 1 ] && return 0
	$@ || err failed executing: "$@"
}

ensure() {  
	{ set +x; } 2>/dev/null
        [ $# -lt 1 ] && return 0
	$@ || err failed executing: "$@"
	{ set -x; } 2>/dev/null
}

rxrand="$(base64 < /dev/random | tr -d '/+=' | head -c 10)"

opwd="$(pwd)"

ensure_noset mkdir /tmp/websvgtex-$rxrand
ensure_noset cd /tmp/websvgtex-$rxrand

cat >m.tex <<EOF
\documentclass[preview]{standalone}
\usepackage{amsmath}
\begin{document}
EOF

cat /dev/stdin >>m.tex

cat >>m.tex <<EOF
\end{document}
EOF

if [ -z "$1" ]
then
	export_filename="m.svg"
else
	export_filename="$1"
fi

{ set -x; } 2>/dev/null

ensure latex m.tex
ensure latex m.tex
ensure dvips m.dvi
ensure inkscape m.ps --export-plain-svg --export-filename="$export_filename"

ensure mv "$export_filename" "$opwd"