2006-12-12 07:04:09 +00:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2006-12-28 02:20:09 +00:00
|
|
|
REQUIRED="pdflatex"
|
2007-01-08 19:55:34 +00:00
|
|
|
SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
|
2006-12-12 07:04:09 +00:00
|
|
|
|
|
|
|
### common.sh
|
|
|
|
|
2006-12-22 20:16:03 +00:00
|
|
|
### tempdir.sh
|
2006-12-12 07:04:09 +00:00
|
|
|
|
2006-12-22 20:16:03 +00:00
|
|
|
texname=output
|
|
|
|
logfile=$THIS_TEMPDIR/log
|
2006-12-12 07:04:09 +00:00
|
|
|
|
2007-01-09 04:10:24 +00:00
|
|
|
pandoc -s -r markdown -w latex "$@" -o $THIS_TEMPDIR/$texname.tex || exit $?
|
2006-12-12 07:04:09 +00:00
|
|
|
|
2007-01-08 19:55:34 +00:00
|
|
|
if [ "$OUTPUT" = "-" ]; then
|
|
|
|
firstinfile="$(echo $ARGS | sed -ne '1p')"
|
|
|
|
firstinfilebase="${firstinfile%.*}"
|
|
|
|
destname="${firstinfilebase:-stdin}.pdf"
|
|
|
|
else
|
|
|
|
destname="$OUTPUT"
|
|
|
|
fi
|
2006-12-12 07:04:09 +00:00
|
|
|
|
|
|
|
(
|
2007-01-08 21:50:58 +00:00
|
|
|
origdir=$(pwd)
|
2006-12-12 07:04:09 +00:00
|
|
|
cd $THIS_TEMPDIR
|
2007-01-08 21:50:58 +00:00
|
|
|
TEXINPUTS=$origdir:$TEXINPUTS:
|
2007-01-08 21:54:10 +00:00
|
|
|
export TEXINPUTS
|
2007-01-09 04:10:24 +00:00
|
|
|
finished=no
|
|
|
|
runs=0
|
|
|
|
while [ $finished = "no" ]; do
|
|
|
|
pdflatex -interaction=batchmode $texname.tex >/dev/null || {
|
|
|
|
errcode=$?
|
|
|
|
err "${THIS}: pdfLaTeX failed with error code $errcode"
|
|
|
|
[ -f $texname.log ] && {
|
|
|
|
err "${THIS}: error context:"
|
|
|
|
sed -ne '/^!/,/^[[: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 $errcode
|
2007-01-09 02:07:48 +00:00
|
|
|
}
|
2007-01-09 04:10:24 +00:00
|
|
|
if [ $runs -lt 3 ] &&
|
|
|
|
grep -q "LaTeX Warning: There were undefined references." $texname.log; then
|
|
|
|
runs=$(($runs + 1))
|
|
|
|
if grep -q "LaTeX Warning:.*[Cc]itation" $texname.log &&
|
|
|
|
! bibtex $texname >/dev/null 2>&1 >bibtex.err; then
|
|
|
|
if [ $runs -gt 2 ]; then
|
|
|
|
err "${THIS}: bibtex warning messages:"
|
|
|
|
cat bibtex.err
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
finished=yes
|
|
|
|
fi
|
|
|
|
done
|
2006-12-22 20:16:03 +00:00
|
|
|
) || exit $?
|
2006-12-12 07:04:09 +00:00
|
|
|
|
|
|
|
is_target_exists=
|
2006-12-22 20:16:03 +00:00
|
|
|
if [ -f "$destname" ]; then
|
2006-12-12 07:04:09 +00:00
|
|
|
is_target_exists=1
|
2006-12-22 20:16:03 +00:00
|
|
|
mv "$destname" "$destname~"
|
2006-12-12 07:04:09 +00:00
|
|
|
fi
|
|
|
|
|
2006-12-22 20:16:03 +00:00
|
|
|
mv -f $THIS_TEMPDIR/$texname.pdf "$destname"
|
2006-12-12 07:04:09 +00:00
|
|
|
|
2006-12-22 20:16:03 +00:00
|
|
|
errn "Created $destname"
|
2006-12-12 07:04:09 +00:00
|
|
|
[ -z "$is_target_exists" ] || {
|
2006-12-22 20:16:03 +00:00
|
|
|
errn " (previous file has been backed up as $destname~)"
|
2006-12-12 07:04:09 +00:00
|
|
|
}
|
|
|
|
err .
|