aboutsummaryrefslogtreecommitdiff
path: root/latex2markdown
blob: 8f935aef5041d5f13dde8b36f74e4a6fa9e05d7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh -e
# runs pandoc to convert latex to markdown

pathfind () { # portable which(1), code taken from Debian Developer's Reference
    OLDIFS="$IFS"
    IFS=:
    for _p in $PATH; do
        if [ -x "$_p/$*" ]; then
            IFS="$OLDIFS"
            return 0
        fi
    done
    IFS="$OLDIFS"
    return 1
}

for p in pandoc; do
    pathfind $p || {
        echo >&2 "You need '$p' to use this program!"
        exit 1
    }
done

ALL="$*"
ARGS=${ALL%% -- *} # only the part before ' -- ' delimiters is relevant
set -- $ARGS

REST=${ALL#$ARGS}; REST=${REST#--}
PANDOC_OPTS=${REST:-$PANDOC_OPTS}

iconv -t utf-8 $* | pandoc $PANDOC_OPTS -r latex -w markdown -s | \
    iconv -f utf-8