diff options
-rwxr-xr-x | bin/tex2pdf | 72 |
1 files changed, 33 insertions, 39 deletions
diff --git a/bin/tex2pdf b/bin/tex2pdf index aea0d56..5ed49b2 100755 --- a/bin/tex2pdf +++ b/bin/tex2pdf @@ -10,29 +10,25 @@ input_suffix=".tex" probe_suffix="tex" output_suffix=".pdf" -function get_filename() -{ - local base=$(basename ${1}) +get_filename() { + local base="$(basename "${1}")" filename="${base%.*}" } -function get_dirname() -{ - dirname="$(dirname ${1})" +get_dirname() { + dirname="$(dirname "${1}")" } -function probe_extension() -{ +probe_extension() { local extension="${1##*.}" - if [ ${extension} != ${probe_suffix} ]; then + if [ "${extension}" != "${probe_suffix}" ]; then echo "File extension (${extension}) is not ${probe_suffix}. Exiting..." exit 1 fi return 0 } -function probe_tools() -{ +probe_tools() { if [ ! -x /usr/bin/pdflatex ]; then echo "/usr/bin/pdflatex not available. Exiting..." exit 1 @@ -48,60 +44,56 @@ function probe_tools() return 0 } -function create_pdf() -{ - cd ${dirname} +create_pdf() { + cd "${dirname}" set +e pdflatex \ -interaction=nonstopmode \ -shell-escape \ - ${filename}${input_suffix} > /dev/null - bibtex ${filename}.aux - makeglossaries ${filename} + "${filename}${input_suffix}" > /dev/null + bibtex "${filename}.aux" + makeglossaries "${filename}" pdflatex \ -interaction=nonstopmode \ -shell-escape \ - ${filename}${input_suffix} > /dev/null + "${filename}${input_suffix}" > /dev/null pdflatex \ -interaction=nonstopmode \ -shell-escape \ - ${filename}${input_suffix} + "${filename}${input_suffix}" set -e - cd ${initial_pwd} + cd "${initial_pwd}" return 0 } -function check_mupdf_pid() -{ +check_mupdf_pid() { set +e - mupdf_pid=$(ps aux | grep "mupdf ${dirname}/${filename}${output_suffix}" | grep -v "grep" | awk '{print $2}') + mupdf_pid="$(ps aux | grep "mupdf ${dirname}/${filename}${output_suffix}" | grep -v "grep" | awk '{print $2}')" set -e } -function show_pdf() -{ +show_pdf() { check_mupdf_pid echo "mupdf: ${dirname}/${filename}${output_suffix}." - if [ ! -z $mupdf_pid ]; then - kill -SIGHUP ${mupdf_pid} + if [ -n "$mupdf_pid" ]; then + kill -SIGHUP "${mupdf_pid}" else - mupdf ${dirname}/${filename}${output_suffix} & + DISPLAY=':0' mupdf "${dirname}/${filename}${output_suffix}" & fi } -function cleanup() -{ - rm -f ${dirname}/*.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lol,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} \ - ${dirname}/*/*.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lol,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} \ - *.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lol,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} \ - */*.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} +cleanup() { + rm -f "${dirname}/"*.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lol,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} \ + "${dirname}/"*/*.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lol,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} \ + ./*.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lol,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} \ + ./*/*.{acn,acr,alg,aux,bbl,bcf,blg,dvi,glg,glo,gls,glsdefs,idx,ist,lof,log,lot,nav,out,run.xml,snm,toc,upa,upb,vrb,xdy} } render_diags() { echo "Rendering diagrams to pdfs." if [ -d "${dirname}/diag/" ] && [ -x /usr/bin/seqdiag ] ; then for _diag in "${dirname}/diag/"*.diag; do - seqdiag -T 'PDF' "${_diag}" + seqdiag -T 'pdf' "${_diag}" done fi } @@ -111,15 +103,17 @@ render_svgs() { for dir in "${dirname}/images" "${dirname}/../images"; do if [ -d "${dir}" ]; then for svg in "${dir}/"*.svg; do - inkscape -D -z -A "${svg%\.svg}".pdf "${svg}" + if [ -f "${svg}" ]; then + inkscape -D -z -A "${svg%\.svg}".pdf "${svg}" + fi done fi done } -probe_extension $1 -get_filename $1 -get_dirname $1 +probe_extension "$1" +get_filename "$1" +get_dirname "$1" render_diags render_svgs echo "tex2pdf: Converting $filename$input_suffix to $filename$output_suffix." |