#!/bin/sh -e REQUIRED="pdflatex" ### common.sh ### tempdir.sh texname=output logfile=$THIS_TEMPDIR/log if ! pandoc -s -d -r markdown -w latex "$@" >$THIS_TEMPDIR/$texname.tex \ 2>$logfile; then [ -f $logfile ] && sed -e 's/^pandoc/markdown2pdf/g' \ -e '/^INPUT=/d' -e '/^OUTPUT=/d' \ -e '/^[[:space:]]*\(-f\|-t\|-s\|-R\|-S\|-m\|-i\|-c\|-T\|-D\|-d\)/,/./d'\ -e 's/(implies -s)//g' $logfile >&2 exit 1 fi outfile="$(sed -ne 's/^OUTPUT=//p' $logfile)" IFS="$NEWLINE" set -- $(sed -ne 's/^INPUT=//p' $logfile) firstinfilebase="${1%.*}" defaultdest="${firstinfilebase:-stdin}.pdf" destname="${outfile:-$defaultdest}" ( cd $THIS_TEMPDIR if ! pdflatex -interaction=batchmode $texname.tex >/dev/null 2>&1; then err "${THIS}: pdfLaTeX error context:" sed -ne '/^![[:space:]]/,/^[[:space:]]*$/p' \ -ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \ -ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2 if grep -q "File \`ucs.sty' not found" $texname.log; then err "${THIS}: Please install the 'unicode' package from CTAN:" err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/" fi if grep -q "File \`fancyvrb.sty' not found" $texname.log; then err "${THIS}: Please install the 'fancyvrb' package from CTAN:" err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/" fi exit 1 fi ) || exit $? is_target_exists= if [ -f "$destname" ]; then is_target_exists=1 mv "$destname" "$destname~" fi mv -f $THIS_TEMPDIR/$texname.pdf "$destname" errn "Created $destname" [ -z "$is_target_exists" ] || { errn " (previous file has been backed up as $destname~)" } err .