@@ -1,34 +1,47 @@
2# converts markdown to latex, then uses latex to make a PDF
2# converts markdown to latex, then uses latex to make a PDF
4+pathfind () { # portable which(1), code taken from Debian Developer's Reference
8+ if [ -x "$_p/$*" ]; then
4for p in pandoc pdflatex; do
17for p in pandoc pdflatex; do
5− which $p >/dev/null 2>&1 || {
18+ pathfind $p || {
6− echo >&2 "You need '$p' to use this program!"
19+ echo >&2 "You need '$p' to use this program!"
12for option; do
25for option; do
13 if [ -n "$prev" ]; then
26 if [ -n "$prev" ]; then
14− eval "$prev=\$option"
27+ eval "$prev=\$option"
19 optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
32 optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
20 case $option in
33 case $option in
21 -h | --h | --help )
34 -h | --h | --help )
24 -o | --o | --output )
37 -o | --o | --output )
25− prev=outfile
38+ prev=outfile
27 -o=* | --o=* | --output=* )
40 -o=* | --o=* | --output=* )
28− outfile=$optarg
41+ outfile=$optarg
30 -* ) echo >&2 "$0: unknown option: $option; aborting"
43 -* ) echo >&2 "$0: unknown option: $option; aborting"
31− exit 1 ;;
44+ exit 1 ;;
32 * ) break ;;
45 * ) break ;;
@@ -41,9 +54,9 @@ done
42if [ -z "$outfile" ]; then
55if [ -z "$outfile" ]; then
43 if [ -n "$infile" ]; then
56 if [ -n "$infile" ]; then
44− outfile=${infile%.*}.pdf
57+ outfile=${infile%.*}.pdf
46− outfile='stdin.pdf' # input is STDIN, since no argument given
59+ outfile='stdin.pdf' # input is STDIN, since no argument given
@@ -61,9 +74,9 @@ pandoc $PANDOC_OPTS -w latex -s | \
61iconv -f utf-8 > $TEMP/$BASE.tex && (
74iconv -f utf-8 > $TEMP/$BASE.tex && (
63 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
76 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
64− echo >&2 "LaTeX errors:"
77+ echo >&2 "LaTeX errors:"
65− cat >&2 $BASE.log
78+ cat >&2 $BASE.log
68) || exit $?
81) || exit $?