2006-12-12 08:04:09 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2006-12-28 03:20:09 +01:00
|
|
|
REQUIRED="pdflatex"
|
2007-01-08 20:55:34 +01:00
|
|
|
SYNOPSIS="converts markdown-formatted text to PDF, using 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
|
|
|
|
2007-01-09 07:11:29 +01:00
|
|
|
pandoc -s -r markdown -w latex "$@" -o $THIS_TEMPDIR/$texname.tex
|
2006-12-12 08:04:09 +01:00
|
|
|
|
2007-01-08 20:55:34 +01:00
|
|
|
if [ "$OUTPUT" = "-" ]; then
|
|
|
|
firstinfile="$(echo $ARGS | sed -ne '1p')"
|
|
|
|
firstinfilebase="${firstinfile%.*}"
|
|
|
|
destname="${firstinfilebase:-stdin}.pdf"
|
|
|
|
else
|
|
|
|
destname="$OUTPUT"
|
|
|
|
fi
|
2006-12-12 08:04:09 +01:00
|
|
|
|
|
|
|
(
|
2007-01-08 22:50:58 +01:00
|
|
|
origdir=$(pwd)
|
2006-12-12 08:04:09 +01:00
|
|
|
cd $THIS_TEMPDIR
|
2007-01-08 22:50:58 +01:00
|
|
|
TEXINPUTS=$origdir:$TEXINPUTS:
|
2007-01-08 22:54:10 +01:00
|
|
|
export TEXINPUTS
|
2007-01-09 05:10:24 +01: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
|
2007-07-22 22:14:20 +02:00
|
|
|
if grep -q "File \`ulem.sty' not found" $texname.log; then
|
|
|
|
err "${THIS}: Please install the 'ulem' package from CTAN:"
|
|
|
|
err " http://www.ctan.org/tex-archive/macros/latex/contrib/misc/ulem.sty"
|
|
|
|
fi
|
2007-01-09 05:10:24 +01:00
|
|
|
}
|
|
|
|
exit $errcode
|
2007-01-09 03:07:48 +01:00
|
|
|
}
|
2007-01-09 05:10:24 +01:00
|
|
|
if [ $runs -lt 3 ] &&
|
2007-07-08 18:40:07 +02:00
|
|
|
((grep -q "LaTeX Warning: There were undefined references." $texname.log) ||
|
2007-07-16 09:26:03 +02:00
|
|
|
(echo "$@" | grep -q -- "--toc\|--table-of-contents")); then
|
2007-01-09 05:10:24 +01:00
|
|
|
runs=$(($runs + 1))
|
2007-01-09 07:38:15 +01:00
|
|
|
if grep -q "LaTeX Warning:.*[Cc]itation" $texname.log; then
|
|
|
|
bibtex $texname 2>&1 >bibtex.err
|
2007-01-09 05:10:24 +01:00
|
|
|
if [ $runs -gt 2 ]; then
|
2007-01-09 07:38:15 +01:00
|
|
|
if grep -q "error message" bibtex.err ||
|
|
|
|
grep -q "Warning" bibtex.err; then
|
|
|
|
cat bibtex.err >&2
|
|
|
|
fi
|
2007-01-09 05:10:24 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
finished=yes
|
|
|
|
fi
|
|
|
|
done
|
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 .
|