summaryrefslogtreecommitdiff
path: root/gen/docs/convert.sh
blob: 047eb6359a3f2b5070de6eedf7bebe0ec491e76c (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
#!/bin/sh
# convert.sh — Convert generated Markdown ISA doc to PDF
# Usage: ./convert.sh [input.md] [output.pdf]
#
# Requires: pandoc + xelatex (or wkhtmltopdf)
# Install: brew install pandoc mactex  (macOS)
#          apt install pandoc texlive   (Linux)

set -e

INPUT="${1:-../../doc/spec/isa_reference.md}"
OUTPUT="${2:-../../doc/spec/isa_reference.pdf}"
DIR="$(cd "$(dirname "$OUTPUT")" && pwd)"
BASE="$(basename "$OUTPUT")"

echo "Converting: $INPUT → $OUTPUT"

if command -v pandoc >/dev/null 2>&1; then
    if command -v xelatex >/dev/null 2>&1; then
        pandoc "$INPUT" \
            -o "$OUTPUT" \
            --pdf-engine=xelatex \
            -V geometry:margin=1in \
            -V colorlinks=true \
            -V linkcolor=blue \
            -V toccolor=blue \
            -V mainfont="Times New Roman" \
            -V monofont="Courier New" \
            --toc --toc-depth=3 \
            --highlight-style=tango
        echo "PDF generated: $OUTPUT"
    elif command -v wkhtmltopdf >/dev/null 2>&1; then
        DIR="$(dirname "$INPUT")"
        pandoc "$INPUT" \
            -o "${DIR}/isa_reference.html" \
            --self-contained \
            --toc --toc-depth=3
        wkhtmltopdf \
            --margin-top 20mm \
            --margin-bottom 20mm \
            --margin-left 15mm \
            --margin-right 15mm \
            --toc \
            "${DIR}/isa_reference.html" "$OUTPUT"
        echo "PDF generated: $OUTPUT"
    else
        echo "Error: No PDF engine found."
        echo "Install: brew install pandoc mactex (macOS)"
        echo "     or: apt install pandoc texlive-latex-base (Linux)"
        exit 1
    fi
else
    echo "Error: pandoc not found. Install it first."
    exit 1
fi