initial setup of thesis repository
[cluster_expansion_thesis.git] / little_helpers / tikz / sklatex.sh
blobce626eb4536a12891bf439297e360fb6cd3cf625
1 #!/bin/bash -eu
3 pdf_viewer="xpdf -z page "
5 show_pdf=""
6 #Default scaling
7 scaling="0.3"
8 #Parse options
9 while getopts "phs:" optionName
11 case "${optionName}" in
12 p) show_pdf="yes";;
13 s) scaling=${OPTARG} ;;
14 h) echo -e "Usage: ${0} [-p] SK_FILE \n ";
15 exit;;
16 esac
17 done
19 #Switch to not processed arguments
20 shift $(($OPTIND - 1))
23 if [ ${#} -eq 0 ]
24 then
25 ${0} -h
26 exit
29 sk=${1}
31 trunk=$(basename ${sk} .sk)
32 pdf=${trunk}.pdf
33 tex=${trunk}.tex
35 #Change language to tikz if not set
36 tmp_sk=$(mktemp)
37 if [ ! "$(grep "language\s*tikz" ${sk})" ]
38 then
39 cp ${sk} ${tmp_sk}
40 echo "global {language tikz}" >> ${tmp_sk}
41 sk=${tmp_sk}
44 #run sketch
45 sketch ${sk} -Te -o ${tex}
46 rm -f ${tmp_sk}
48 #Adapt
49 adapt_sk.sh -s ${scaling} ${tex}
51 #TeX
52 pdflatex ${tex} >/dev/null
54 if [ "${show_pdf}" = "yes" ]
55 then
56 ${pdf_viewer} ${pdf} &