@@ -1,4 +1,4 @@
1−#!/bin/sh -e
1+#!/bin/sh
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[ -n "$(which pandoc)" ] || {
4[ -n "$(which pandoc)" ] || {
@@ -10,17 +10,55 @@
13−TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
13+outfile=
14−trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
14+for option; do
15+ if [ -n "$prev" ]; then
16+ eval "$prev=\$option"
21+ optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')
26+ -o | --o | --output )
29+ -o=* | --o=* | --output=* )
32+ -* ) echo >&2 "$0: unknown option: $option; aborting"
16−if [ -z "$1" ]; then
38+if [ "$help" = "yes" ]; then
39+ echo "Usage: $0 [-o|--output output-file] [input-file]"
44+if [ -z "$outfile" ]; then
45+ if [ -n "$infile" ]; then
46+ outfile=${infile%.*}.pdf
17− BASE='stdin' # input is STDIN, since no argument given
48+ outfile='stdin.pdf' # input is STDIN, since no argument given
57+TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
58+trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
23−mkdir -p $TEMP && iconv -t utf-8 $* | pandoc -w latex -s > $TEMP/$BASE.tex
61+iconv -t utf-8 $infile | pandoc -w latex -s > $TEMP/$BASE.tex
26 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
64 if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
@@ -35,10 +73,10 @@ if [ -f $BASE.pdf ]; then
35 is_target_exists=1
73 is_target_exists=1
38−cp --suffix=~ --backup $TEMP/$BASE.pdf .
76+mv --suffix=~ --backup $TEMP/$BASE.pdf $outfile
40−echo -n >&2 "Created $BASE.pdf"
78+echo -n >&2 "Created $outfile"
41[ -z "$is_target_exists" ] || {
79[ -z "$is_target_exists" ] || {
42− echo -n >&2 " (previous file has been backed up as '$BASE.pdf~')"
80+ echo -n >&2 " (previous file has been backed up as '$outfile~')"