@@ -10,7 +10,7 @@ SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
1010texname=output
1111logfile=$THIS_TEMPDIR/log
1212
13−pandoc -s -r markdown -w latex "$@" -o $THIS_TEMPDIR/$texname.tex 2>$logfile
13+pandoc -s -r markdown -w latex "$@" -o $THIS_TEMPDIR/$texname.tex || exit $?
1414
1515if [ "$OUTPUT" = "-" ]; then
1616 firstinfile="$(echo $ARGS | sed -ne '1p')"
@@ -25,25 +25,42 @@ fi
2525 cd $THIS_TEMPDIR
2626 TEXINPUTS=$origdir:$TEXINPUTS:
2727 export TEXINPUTS
28− pdflatex -interaction=batchmode $texname.tex >/dev/null || {
29− errcode=$?
30− err "${THIS}: pdfLaTeX failed with error code $errcode"
31− [ -f $texname.log ] && {
32− err "${THIS}: error context:"
33− sed -ne '/^!/,/^[[:space:]]*$/p' \
34− -ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \
35− -ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2
36− if grep -q "File \`ucs.sty' not found" $texname.log; then
37− err "${THIS}: Please install the 'unicode' package from CTAN:"
38− err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
39− fi
40− if grep -q "File \`fancyvrb.sty' not found" $texname.log; then
41− err "${THIS}: Please install the 'fancyvrb' package from CTAN:"
42− err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
43− fi
28+ finished=no
29+ runs=0
30+ while [ $finished = "no" ]; do
31+ pdflatex -interaction=batchmode $texname.tex >/dev/null || {
32+ errcode=$?
33+ err "${THIS}: pdfLaTeX failed with error code $errcode"
34+ [ -f $texname.log ] && {
35+ err "${THIS}: error context:"
36+ sed -ne '/^!/,/^[[:space:]]*$/p' \
37+ -ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \
38+ -ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2
39+ if grep -q "File \`ucs.sty' not found" $texname.log; then
40+ err "${THIS}: Please install the 'unicode' package from CTAN:"
41+ err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
42+ fi
43+ if grep -q "File \`fancyvrb.sty' not found" $texname.log; then
44+ err "${THIS}: Please install the 'fancyvrb' package from CTAN:"
45+ err " http://www.ctan.org/tex-archive/macros/latex/contrib/fancyvrb/"
46+ fi
47+ }
48+ exit $errcode
4449 }
45− exit $errcode
46− }
50+ if [ $runs -lt 3 ] &&
51+ grep -q "LaTeX Warning: There were undefined references." $texname.log; then
52+ runs=$(($runs + 1))
53+ if grep -q "LaTeX Warning:.*[Cc]itation" $texname.log &&
54+ ! bibtex $texname >/dev/null 2>&1 >bibtex.err; then
55+ if [ $runs -gt 2 ]; then
56+ err "${THIS}: bibtex warning messages:"
57+ cat bibtex.err
58+ fi
59+ fi
60+ else
61+ finished=yes
62+ fi
63+ done
4764) || exit $?
4865
4966is_target_exists=