Manual: build the PDF with XeLaTeX in IBM Plex

docs/md2tex.py converts docs/basic-manual.md (still the only source) to
LaTeX via python-markdown's HTML; build-manual.sh typesets it with XeLaTeX
instead of printing HTML from Chrome. A title page, contents with page
numbers, section openers, running heads, Carbon-style tables and code
panels. Code blocks inside numbered lists now render as code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
brad ArantandClaude Opus 5.5 committed 2026-12-01 19:41:27 -08:00
1 parent 2e668c708f
commit 1e44ce4383
4 files changed
+437 -25

No files matched your search

+20 -25
View File
@@ -1,29 +1,24 @@
#!/bin/bash
# Turn docs/basic-manual.md into docs/basic-manual.pdf (needs python3-markdown and Chrome).
# Turn docs/basic-manual.md into docs/basic-manual.pdf.
# The Markdown is the only source: md2tex.py converts it to LaTeX, and XeLaTeX
# typesets it in IBM Plex. Needs python3-markdown, XeLaTeX (texlive-xetex,
# -latex-extra for KOMA-Script, tcolorbox, xltabular) and the IBM Plex fonts
# in /usr/share/fonts/truetype/ibm-plex (fonts-ibm-plex).
set -e
cd "$(dirname "$0")"
python3 - <<'PY'
import markdown
body = markdown.markdown(open("basic-manual.md").read(), extensions=["tables", "fenced_code"])
css = """
@page { size: A4; margin: 18mm 16mm; }
body { font-family: "DejaVu Serif", Georgia, serif; font-size: 10.5pt; line-height: 1.45; color: #111; }
h1 { font-size: 24pt; margin: 0 0 4pt; }
h1 + p { font-size: 12pt; color: #444; margin-bottom: 18pt; }
h2 { font-size: 15pt; border-bottom: 1px solid #999; padding-bottom: 2pt; margin-top: 22pt;
page-break-after: avoid; }
h3 { font-size: 12pt; margin-top: 14pt; page-break-after: avoid; }
code, pre { font-family: "DejaVu Sans Mono", monospace; font-size: 9pt; }
pre { background: #f2f2f2; border-left: 3px solid #4a7; padding: 6pt 8pt; page-break-inside: avoid; }
table { border-collapse: collapse; margin: 6pt 0; page-break-inside: avoid; }
th, td { border: 1px solid #bbb; padding: 3pt 6pt; vertical-align: top; text-align: left; }
th { background: #e8e8e8; }
"""
open("basic-manual.html", "w").write(
"<!doctype html><html><head><meta charset='utf-8'><title>Basys 3 RISC-V BASIC</title>"
"<style>%s</style></head><body>%s</body></html>" % (css, body))
PY
google-chrome --headless --disable-gpu --no-pdf-header-footer \
--print-to-pdf="$PWD/basic-manual.pdf" "file://$PWD/basic-manual.html" 2>/dev/null
rm basic-manual.html
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
python3 md2tex.py basic-manual.md "$work/basic-manual.tex"
# three passes: contents, then page numbers in the contents, then settled
for pass in 1 2 3; do
if ! (cd "$work" && xelatex -interaction=nonstopmode -halt-on-error basic-manual.tex >/dev/null); then
grep -A8 '^!' "$work/basic-manual.log" >&2 || tail -40 "$work/basic-manual.log" >&2
exit 1
fi
done
if grep -q 'Missing character' "$work/basic-manual.log"; then
echo "warning: characters missing from the fonts:" >&2
grep 'Missing character' "$work/basic-manual.log" | sort -u >&2
fi
cp "$work/basic-manual.pdf" basic-manual.pdf
echo "wrote docs/basic-manual.pdf"