aboutsummaryrefslogtreecommitdiff
path: root/src/wrappers/markdown2pdf.in
diff options
context:
space:
mode:
authorroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-12 07:04:09 +0000
committerroktas <roktas@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-12 07:04:09 +0000
commit426cbadfef6c26323faedcab2cd5ea7efa64d1bb (patch)
treee16afb28eec790226a7b0524b8fb325594232e5c /src/wrappers/markdown2pdf.in
parent6411ea7466f67f94816c541a22abb7249d36c377 (diff)
downloadpandoc-426cbadfef6c26323faedcab2cd5ea7efa64d1bb.tar.gz
Merge changes in branches/wrappers into trunk.
[in trunk] svn merge -r105:HEAD \ https://pandoc.googlecode.com/svn/branches/wrappers git-svn-id: https://pandoc.googlecode.com/svn/trunk@177 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/wrappers/markdown2pdf.in')
-rw-r--r--src/wrappers/markdown2pdf.in64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/wrappers/markdown2pdf.in b/src/wrappers/markdown2pdf.in
new file mode 100644
index 000000000..838767224
--- /dev/null
+++ b/src/wrappers/markdown2pdf.in
@@ -0,0 +1,64 @@
+#!/bin/sh -e
+# converts markdown to latex, then uses latex to make a PDF
+
+REQUIRED=pdflatex
+
+### common.sh
+
+outfile=
+while getopts o:h opt; do
+ case $opt in
+ o) outfile="$OPTARG" ;;
+ h|?) usage "[-o output_file] [-h] [input_file]..."; exit 2 ;;
+ esac
+done
+
+shift $(($OPTIND - 1))
+
+### postopts.sh
+
+### checkin.sh
+
+if [ -z "$outfile" ]; then
+ if [ -n "$1" ]; then
+ outfile="${1%.*}"
+ else
+ outfile="stdin" # input is STDIN, since no argument given
+ fi
+fi
+case "$outfile" in
+*.*) ;; # skip appending extension if one is already present
+*) outfile="${outfile%.*}.pdf";;
+esac
+
+### tempdir.sh
+
+# We should use a filename without white spaces for pdflatex.
+TEXNAME=$THIS
+
+to_utf8 "$@" | runpandoc -w latex -s >$THIS_TEMPDIR/$TEXNAME.tex
+(
+ cd $THIS_TEMPDIR
+ if ! pdflatex -interaction=batchmode $TEXNAME.tex >/dev/null 2>&1; then
+ err "LaTeX errors:"
+ from_utf8 $TEXNAME.log | sed -ne '/^!/,/^ *$/p' >&2
+ if grep -q "File \`ucs.sty' not found" $TEXNAME.log; then
+ err "Please install the 'unicode' package from ctan.org."
+ fi
+ exit 1
+ fi
+)
+
+is_target_exists=
+if [ -f "$outfile" ]; then
+ is_target_exists=1
+ mv -f "$outfile" "$outfile~"
+fi
+
+mv -f $THIS_TEMPDIR/$TEXNAME.pdf "$outfile"
+
+errn "Created '$outfile'"
+[ -z "$is_target_exists" ] || {
+ errn " (previous file has been backed up as '$outfile~')"
+}
+err .