aboutsummaryrefslogtreecommitdiff
path: root/markdown2pdf
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-10-17 14:22:29 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-10-17 14:22:29 +0000
commitdf7b68225101966051f8b592a27127bf789eb81e (patch)
treea063e97ed58d0bdb2cbb5a95c3e8c1bcce54aa00 /markdown2pdf
parente7dbfef4d8aa528d9245424e9c372e900a774c90 (diff)
downloadpandoc-df7b68225101966051f8b592a27127bf789eb81e.tar.gz
initial import
git-svn-id: https://pandoc.googlecode.com/svn/trunk@2 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'markdown2pdf')
-rw-r--r--markdown2pdf44
1 files changed, 44 insertions, 0 deletions
diff --git a/markdown2pdf b/markdown2pdf
new file mode 100644
index 000000000..6a76aab7d
--- /dev/null
+++ b/markdown2pdf
@@ -0,0 +1,44 @@
+#!/bin/sh -e
+# converts markdown to latex, then uses latex to make a PDF
+
+[ -n "$(which pandoc)" ] || {
+ echo >&2 "You need 'pandoc' to use this program!"
+ exit 1
+}
+[ -n "$(which pdflatex)" ] || {
+ echo >&2 "You need 'pdflatex' to use this program!"
+ exit 1
+}
+
+TEMP=${TMPDIR-/tmp}/markdown2pdf.$$
+trap "status=$?; rm -rf $TEMP; exit $status" 0 INT
+
+if [ -z "$1" ]; then
+ BASE='stdin' # input is STDIN, since no argument given
+else
+ filename=${1##*/}
+ BASE=${filename%\.*}
+fi
+
+mkdir -p $TEMP && iconv -t utf-8 $* | pandoc -w latex -s > $TEMP/$BASE.tex
+(
+ cd $TEMP
+ if ! pdflatex -interaction=batchmode $BASE.tex >/dev/null 2>&1; then
+ echo >&2 "LaTeX errors:"
+ cat >&2 $BASE.log
+ exit 1
+ fi
+) || exit $?
+
+is_target_exists=
+if [ -f $BASE.pdf ]; then
+ is_target_exists=1
+fi
+
+cp --suffix=~ --backup $TEMP/$BASE.pdf .
+
+echo -n >&2 "Created $BASE.pdf"
+[ -z "$is_target_exists" ] || {
+ echo -n >&2 " (previous file has been backed up as '$BASE.pdf~')"
+}
+echo >&2 .