From c538086f5ad82d57c43726cb4536e36ad5c6320a Mon Sep 17 00:00:00 2001 From: Dave Tang Date: Tue, 23 Jun 2026 16:31:48 +0900 Subject: Add LaTeX support --- scripts/setup.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'scripts/setup.sh') diff --git a/scripts/setup.sh b/scripts/setup.sh index d77d23e..bdebe9b 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -6,8 +6,8 @@ # bash setup-docsify.sh # # Downloads Docsify core, the search plugin, the Vue theme, the copy-to-clipboard -# plugin, and extra Prism languages (bash, yaml, python, r) — all -# served locally, no external CDN dependencies at runtime. +# plugin, extra Prism languages (bash, yaml, python, r), and KaTeX math rendering — +# all served locally, no external CDN dependencies at runtime. # # Re-running in an existing site is safe: it refreshes the assets and regenerates # index.html, but never overwrites Markdown files (README.md, _sidebar.md, and any @@ -18,6 +18,8 @@ set -euo pipefail # ── Configuration ─────────────────────────────────────────────────────────────── # Use "4" for the latest 4.x release, or pin to a specific version e.g. "4.13.1" DOCSIFY_VERSION="4" +# KaTeX stylesheet/font version — must match the renderer bundled in docsify-katex@1.4.4 +KATEX_VERSION="0.11.1" # ── Argument check ────────────────────────────────────────────────────────────── if [[ $# -gt 0 ]]; then @@ -59,7 +61,7 @@ echo -e " Working in: $(pwd)" # ── Step 1: Directories ───────────────────────────────────────────────────────── step "Step 1 — Creating directory structure" -mkdir -p assets/js assets/css +mkdir -p assets/js assets/css assets/css/fonts ok "assets/js/" ok "assets/css/" @@ -91,6 +93,17 @@ fetch "${CDN}/prismjs@1/components/prism-yaml.min.js" assets/js/prism-yaml.mi fetch "${CDN}/prismjs@1/components/prism-python.min.js" assets/js/prism-python.min.js fetch "${CDN}/prismjs@1/components/prism-r.min.js" assets/js/prism-r.min.js +# Math: docsify-katex@1.4.4 bundles the KaTeX renderer (2.x is broken). KaTeX's +# stylesheet loads its fonts from ./fonts/ beside it, so the woff2 files go in +# assets/css/fonts/. Stylesheet + fonts are pinned to the bundled KaTeX (KATEX_VERSION). +fetch "${CDN}/docsify-katex@1.4.4/dist/docsify-katex.js" assets/js/docsify-katex.js +fetch "${CDN}/katex@${KATEX_VERSION}/dist/katex.min.css" assets/css/katex.min.css +for f in $(grep -oE 'fonts/KaTeX_[^)]+\.woff2' assets/css/katex.min.css | sort -u); do + curl -sL --fail "${CDN}/katex@${KATEX_VERSION}/dist/$f" -o "assets/css/$f" \ + || die "Failed to download: $f" +done +ok "assets/css/fonts/ ($(ls -1 assets/css/fonts | wc -l) KaTeX woff2 files)" + # ── Step 3: index.html ────────────────────────────────────────────────────────── step "Step 3 — Creating index.html" @@ -105,6 +118,7 @@ cat > index.html << 'HTML' My Docs +
@@ -119,6 +133,7 @@ cat > index.html << 'HTML' + @@ -189,7 +204,8 @@ ok "Files: 644 | Directories: 755" # ── Verify ─────────────────────────────────────────────────────────────────────── step "Verifying file layout" -find . -not -path '*/\.*' | sort +find . -not -path '*/\.*' -not -path './assets/css/fonts*' | sort +echo "./assets/css/fonts/ ($(ls -1 assets/css/fonts 2>/dev/null | wc -l) KaTeX woff2 files)" # ── Done ───────────────────────────────────────────────────────────────────────── echo "" @@ -200,3 +216,4 @@ echo -e "Syntax highlighting: html, css, and javascript are built into Docsify;" echo -e "this setup adds bash, yaml, python, and r. To add more languages, download" echo -e "additional prism-.min.js files into assets/js/ and add their