4SYNOPSIS="converts markdown-formatted text to PDF, using pdflatex."
11err () { echo "$*" | fold -s -w ${COLUMNS:-110} >&2; }
12errn () { printf "$*" | fold -s -w ${COLUMNS:-110} >&2; }
15 err "$1 - $2" # short description
16 err "See the $1(1) man page for usage."
21 oldifs="$IFS"; IFS=':'
23 if [ -x "$_p/$*" ] && [ -f "$_p/$*" ]; then
32for p in pandoc $REQUIRED; do
34 err "You need '$p' to use this program!"
39CONF=$(pandoc --dump-args "$@" 2>&1) || {
41 echo "$CONF" | sed -e '/^pandoc \[OPTIONS\] \[FILES\]/,$d' >&2
42 [ $errcode -eq 2 ] && usage "$THIS" "$SYNOPSIS"
46OUTPUT=$(echo "$CONF" | sed -ne '1p')
47ARGS=$(echo "$CONF" | sed -e '1d')
50# As a security measure refuse to proceed if mktemp is not available.
51pathfind mktemp || { err "Couldn't find 'mktemp'; aborting."; exit 1; }
53# Avoid issues with /tmp directory on Windows/Cygwin
55cygwin=$(uname | sed -ne '/^CYGWIN/p')
56if [ -n "$cygwin" ]; then
62THIS_TEMPDIR="$(mktemp -d -t $THIS.XXXXXXXX)" || exit 1
66 [ -z "$THIS_TEMPDIR" ] || rm -rf "$THIS_TEMPDIR"
67 exit $exitcode' 0 1 2 3 13 15
70logfile=$THIS_TEMPDIR/log
72pandoc -s -r markdown -w latex "$@" -o $THIS_TEMPDIR/$texname.tex
74if [ "$OUTPUT" = "-" ]; then
75 firstinfile="$(echo $ARGS | sed -ne '1p')"
76 firstinfilebase="${firstinfile%.*}"
77 destname="${firstinfilebase:-stdin}.pdf"
85 TEXINPUTS=$origdir:$TEXINPUTS:
89 while [ $finished = "no" ]; do
90 pdflatex -interaction=batchmode $texname.tex >/dev/null || {
92 err "${THIS}: pdfLaTeX failed with error code $errcode"
93 [ -f $texname.log ] && {
94 err "${THIS}: error context:"
95 sed -ne '/^!/,/^[[:space:]]*$/p' \
96 -ne '/^[Ll]a[Tt]e[Xx] [Ww]arning/,/^[[:space:]]*$/p' \
97 -ne '/^[Ee]rror/,/^[[:space:]]*$/p' $texname.log >&2
98 if grep -q "File \`ucs.sty' not found" $texname.log; then
99 err "${THIS}: Please install the 'unicode' package from CTAN:"
100 err " http://www.ctan.org/tex-archive/macros/latex/contrib/unicode/"
102 if grep -q "File \`ulem.sty' not found" $texname.log; then
103 err "${THIS}: Please install the 'ulem' package from CTAN:"
104 err " http://www.ctan.org/tex-archive/macros/latex/contrib/misc/ulem.sty"
109 if [ $runs -lt 3 ] &&
110 ((grep -q "LaTeX Warning: There were undefined references." $texname.log) ||
111 (echo "$@" | grep -q -- "--toc\|--table-of-contents")); then
113 if grep -q "LaTeX Warning:.*[Cc]itation" $texname.log; then
114 bibtex $texname 2>&1 >bibtex.err
115 if [ $runs -gt 2 ]; then
116 if grep -q "error message" bibtex.err ||
117 grep -q "Warning" bibtex.err; then
129if [ -f "$destname" ]; then
131 mv "$destname" "$destname~"
134mv -f $THIS_TEMPDIR/$texname.pdf "$destname"
136errn "Created $destname"
137[ -z "$is_target_exists" ] || {
138 errn " (previous file has been backed up as $destname~)"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list