@@ -1,136 +0,0 @@
1−#!/bin/sh -e
2−
3−latexprogram=pdflatex
4−if (echo "$@" | grep -q xetex); then
5− latexprogram=xelatex
6−fi
7−
8−REQUIRED=$latexprogram
9−SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
10−
11−THIS=${0##*/}
12−
13−NEWLINE='
14−'
15−
16−err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
17−errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
18−
19−usage () {
20− err "$1 - $2" # short description
21− err "Options:"
22− pandoc -h | sed -ne '/--strict\|--preserve-tabs\|--tab-stop\|--parse-raw\|--toc\|--xetex\|--number-sections\|--include-in-header\|--include-before-body\|--include-after-body\|--custom-header\|--output\|--template\|--variable\|--help\|--version/p' >&2
23−}
24−
25−# Portable which(1).
26−pathfind () {
27− oldifs="$IFS"; IFS=':'
28− for _p in $PATH; do
29− if [ -x "$_p/$*" ] && [ -f "$_p/$*" ]; then
30− IFS="$oldifs"
31− return 0
32− fi
33− done
34− IFS="$oldifs"
35− return 1
36−}
37−
38−for p in pandoc $REQUIRED; do
39− pathfind $p || {
40− err "You need '$p' to use this program!"
41− exit 1
42− }
43−done
44−
45−if (echo "$@" | grep -q -- "--help\|-h"); then
46− usage "$THIS" "$SYNOPSIS"
47− exit 0
48−fi
49−
50−CONF=$(pandoc --dump-args "$@") || exit $?
51−OUTPUT=$(echo "$CONF" | sed -ne '1p')
52−ARGS=$(echo "$CONF" | sed -e '1d')
53−
54−# As a security measure refuse to proceed if mktemp is not available.
55−pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
56−
57−# Avoid issues with /tmp directory on Windows/Cygwin
58−cygwin=
59−cygwin=$(uname | sed -ne '/^CYGWIN/p')
60−if [ -n "$cygwin" ]; then
61− TMPDIR=.
62− export TMPDIR
63−fi
64−
65−THIS_TEMPDIR=
66−THIS_TEMPDIR="$(mktemp -d -t $THIS.XXXXXXXX)" || exit 1
67−readonly THIS_TEMPDIR
68−
69−trap 'exitcode=$?
70− [ -z "$THIS_TEMPDIR" ] || rm -rf "$THIS_TEMPDIR"
71− exit $exitcode' 0 1 2 3 13 15
72−
73−texname=output
74−logfile=$THIS_TEMPDIR/log
75−
76−pandoc -s -r markdown -w latex "$@" -o $THIS_TEMPDIR/$texname.tex
77−
78−if [ "$OUTPUT" = "-" ]; then
79− firstinfile="$(echo $ARGS | sed -ne '1p')"
80− firstinfilebase="${firstinfile%.*}"
81− destname="${firstinfilebase:-stdin}.pdf"
82−else
83− destname="$OUTPUT"
84−fi
85−
86−(
87− origdir=$(pwd)
88− cd $THIS_TEMPDIR
89− TEXINPUTS=$origdir:$TEXINPUTS:
90− export TEXINPUTS
91− finished=no
92− runs=0
93− while [ $finished = "no" ]; do
94− $latexprogram -interaction=batchmode $texname.tex >/dev/null || {
95− errcode=$?
96− err "${THIS}: $latexprogram failed with error code $errcode"
97− [ -f $texname.log ] && {
98− err "${THIS}: error context:"
99− sed -ne '/^!/,/^[[:space:]]*$/p' \
100− -ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \
101− -ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2
102− if grep -q "File \`ucs.sty' not found" $texname.log; then
103− err "${THIS}: Please install the 'unicode' package from CTAN:"
104− err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
105− fi
106− if grep -q "File \`ulem.sty' not found" $texname.log; then
107− err "${THIS}: Please install the 'ulem' package from CTAN:"
108− err " http://www.ctan.org/tex-archive/macros/latex/contrib/misc/ulem.sty"
109− fi
110− }
111− exit $errcode
112− }
113− if [ $runs -lt 3 ] &&
114− ((grep -q "Warning: There were undefined references." $texname.log) ||
115− (echo "$@" | grep -q -- "--toc\|--table-of-contents")); then
116− runs=$(($runs + 1))
117− if grep -q "LaTeX Warning:.*[Cc]itation" $texname.log; then
118− bibtex $texname 2>&1 >bibtex.err
119− if [ $runs -gt 2 ]; then
120− if grep -q "error message" bibtex.err ||
121− grep -q "Warning" bibtex.err; then
122− cat bibtex.err >&2
123− fi
124− fi
125− fi
126− elif [ $runs -gt 1 ]; then # always run at least twice for pdf bookmarks
127− finished=yes
128− else
129− runs=$(($runs + 1))
130− fi
131− done
132−) || exit $?
133−
134−mv -f $THIS_TEMPDIR/$texname.pdf "$destname"
135−
136−err "Created $destname"