forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cm2pdf
72 lines (64 loc) · 1.44 KB
/
cm2pdf
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
#! /bin/bash
m4file=""
fontsize=10
usage() {
echo "Usage:"
echo "${0##*/} --help"
echo "${0##*/} [options] path/to/file.m4"
echo
echo "--help"
echo " Show this help message."
echo
echo "-f, --fontsize"
echo " Set size of base font, in points."
echo " Supported font sizes are 8, 9, 10, 11, 12, 14, 17 and 20."
exit
}
if [[ "$#" == 0 ]]; then usage; fi
while [[ "$#" != 0 ]]; do
case "${1}" in
-h|--help)
usage;;
-f|--fontsize)
case "${2}" in
8)
fontsize=8;;
9)
fontsize=9;;
10)
fontsize=10;;
11)
fontsize=11;;
12)
fontsize=12;;
14)
fontsize=14;;
17)
fontsize=17;;
20)
fontsize=20;;
*)
echo "Unsupported font size: ${2}"
exit;;
esac
shift; shift;;
*.m4)
m4file="${1}"
shift;;
*)
echo "Unknown option: ${1}"
exit
esac
done
if [[ "${m4file}" == "" ]]; then
echo "No m4 input file"
exit
fi
tempdir=$(mktemp -d)
cp -f "${m4file}" "${tempdir}/source.m4"
pushd "${tempdir}" > /dev/null
m4 -I /usr/share/circuit_macros pgf.m4 source.m4 | dpic -g > source.tex
pdflatex "\documentclass[preview=true]{standalone}\usepackage{tikz,boxdims}\usepackage[${fontsize}pt]{extsizes}\begin{document}\input source.tex\end{document}"
popd > /dev/null
cp "${tempdir}/standalone.pdf" "${m4file%.m4}.pdf"
rm -rf "${tempdir}"