summaryrefslogtreecommitdiff
path: root/groffdown
blob: 60e7721c2e08555a4a21861275b641e0c6f61dea (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh

file=$(readlink -f "$1")
dir=$(dirname "$file")
base="${file%.*}"


output=$( sed -e '1s/---/\.EQ\ndelim\ $$\n\.EN\n/
                        s/title:/\.TL\n/
                        s/author:/\.AU\n/
                        s/date:/\.ND\n/
                        s/institution:/\.AI\n/

                        s/\\begin{abstract}/\.AB/
                        s/\\end{abstract}/\.AE/

                        s/\\begin{equation}/\.EQ/
                        s/\\end{equation}/\.EN/

                        s/\\\$/$delim\ @@$\ $@delim\ $$@/g

                        s/^\#####.\(.*\)/\.NH 5\n\1\n\.PP/g
                        s/^\####.\(.*\)/\.NH 4\n\1\n\.PP/g
                        s/^\###.\(.*\)/\.NH 3\n\1\n\.PP/g
                        s/^\##.\(.*\)/\.NH 2\n\1\n\.PP/g
                        s/^\#.\(.*\)/\.NH 1\n\1\n\.PP/g

                        s/\*\*\*\(.*\)\*\*\*$/\n\.BI\ \"\1\"\ /g
                        s/\*\*\*\(.*\)\*\*\*\(.\)$/\n\.BI\ \"\1\"\ \"\2\"/g
                        s/\*\*\*\(.*\)\*\*\*\(.\)/\n\.BI\ \"\1\"\ \"\2\"\n/g

                        s/\*\*\(.*\)\*\*$/\n\.B\ \"\1\"\ /g
                        s/\*\*\(.*\)\*\*\(.\)$/\n\.B\ \"\1\"\ \"\2\"/g
                        s/\*\*\(.*\)\*\*\(.\)/\n\.B\ \"\1\"\ \"\2\"\n/g

                        s/\*\(.*\)\*$/\n\.I\ \"\1\"\ /g
                        s/\*\(.*\)\*\(.\)$/\n\.I\ \"\1\"\ \"\2\"/g
                        s/\*\(.*\)\*\(.\)/\n\.I\ \"\1\"\ \"\2\"\n/g

                        s/`\(.*\)`$/\n\.CW\ \"\1\"\ /g
                        s/`\(.*\)`\(.\)$/\n\.CW\ \"\1\"\ \"\2\"/g
                        s/`\(.*\)`\(.\)/\n\.CW\ \"\1\"\ \"\2\"\n/g

                        s/\\cite{\(.*\)}/\n\.\[\n\1\n\.\]/g

                        s/^-\ /.IP\ \\(bu\ 2\n/g

                        ' $1)
# echo "$output" | groff -me -ms -kejpt -T pdf > $base.pdf

# This script will compile the md document into a groff .ms file.
#   Good for reviewing compiled .ms text for debugging the ms output
#   as you code.
# echo "$output" > "$base".ms
echo "$output"
# groff -ms $base.ms -T pdf > $base.pdf