2006-12-12 08:04:09 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2006-12-28 03:20:09 +01:00
|
|
|
REQUIRED="pdflatex"
|
2006-12-12 08:04:09 +01:00
|
|
|
|
|
|
|
### common.sh
|
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
### tempdir.sh
|
2006-12-12 08:04:09 +01:00
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
texname=output
|
|
|
|
logfile=$THIS_TEMPDIR/log
|
2006-12-12 08:04:09 +01:00
|
|
|
|
2006-12-28 03:20:09 +01:00
|
|
|
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
|
2006-12-22 21:16:03 +01:00
|
|
|
exit 1
|
2006-12-12 08:04:09 +01:00
|
|
|
fi
|
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
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}"
|
2006-12-12 08:04:09 +01:00
|
|
|
|
|
|
|
(
|
|
|
|
cd $THIS_TEMPDIR
|
2007-01-07 04:17:40 +01:00
|
|
|
if ! pdflatex -interaction=batchmode $texname.tex >$texname.log 2>&1; then
|
|
|
|
shortlog="$(sed -ne 's/^[Ee]rror:*[[:space:]]*//p' $texname.log)"
|
|
|
|
if [ -n "$shortlog" ]; then
|
|
|
|
err "Errors:"
|
|
|
|
err "$shortlog"
|
|
|
|
else
|
|
|
|
# Short log is not available, dump the whole log.
|
|
|
|
err "pdfLaTeX log:"
|
|
|
|
cat $texname.log >&2
|
|
|
|
fi
|
2006-12-22 21:16:03 +01:00
|
|
|
if grep -q "File \`ucs.sty' not found" $texname.log; then
|
|
|
|
err "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 "Please install the 'fancyvrb' package from CTAN:"
|
|
|
|
err "http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
|
2006-12-12 08:04:09 +01:00
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
2006-12-22 21:16:03 +01:00
|
|
|
) || exit $?
|
2006-12-12 08:04:09 +01:00
|
|
|
|
|
|
|
is_target_exists=
|
2006-12-22 21:16:03 +01:00
|
|
|
if [ -f "$destname" ]; then
|
2006-12-12 08:04:09 +01:00
|
|
|
is_target_exists=1
|
2006-12-22 21:16:03 +01:00
|
|
|
mv "$destname" "$destname~"
|
2006-12-12 08:04:09 +01:00
|
|
|
fi
|
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
mv -f $THIS_TEMPDIR/$texname.pdf "$destname"
|
2006-12-12 08:04:09 +01:00
|
|
|
|
2006-12-22 21:16:03 +01:00
|
|
|
errn "Created $destname"
|
2006-12-12 08:04:09 +01:00
|
|
|
[ -z "$is_target_exists" ] || {
|
2006-12-22 21:16:03 +01:00
|
|
|
errn " (previous file has been backed up as $destname~)"
|
2006-12-12 08:04:09 +01:00
|
|
|
}
|
|
|
|
err .
|