Skip to content

Commit

Permalink
Switch from MathJax to KaTeX. fixes zcash#432
Browse files Browse the repository at this point in the history
(zip-guide *incorrectly* said that we were already using KaTeX. This has
been wrong since zcash#645.)

Signed-off-by: Daira-Emma Hopwood <[email protected]>
  • Loading branch information
daira committed Nov 12, 2024
1 parent ba09951 commit 936223b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ endef

define PROCESSMD
$(eval TITLE := $(shell echo '$(patsubst zips/%,%,$(basename $<))' | sed -E 's|zip-0{0,3}|ZIP |;s|draft-|Draft |')$(shell grep -E '^(\.\.)?\s*Title: ' $< |sed -E 's|.*Title||'))
pandoc --from=markdown --to=html $< --output=$@
pandoc --mathjax --from=markdown --to=html $< --output=$@
./edithtml.sh --md $@ "${TITLE}"
endef

Expand Down
29 changes: 21 additions & 8 deletions edithtml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,38 @@ if ! [ -f "$2" ]; then
exit
fi

Math1='<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+" crossorigin="anonymous">'
Math2='<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg" crossorigin="anonymous"></script>'
Math3='<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-43gviWU0YVjaDtb/GhzOouOXtZMP/7XUzwPTstBeZFe/+rCMvRwr4yROQP43s0Xk" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>'
ViewAndStyle='<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css">'

if [ "x$1" = "x--rst" ]; then
sed -i.sedbak 's|</head>|<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css"></head>|' $2
sed -i.sedbak 's|http://cdn.mathjax.org/mathjax/latest/MathJax.js|https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js|' $2
sed -i.sedbak "s|<script src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>|${Math1}\n ${Math2}\n ${Math3}|" $2
sed -i.sedbak "s|</head>|${ViewAndStyle}</head>|" $2
else
cat - "$2" >"$2".prefix <<EOF
cat - >"$2".prefix <<EndOfMdInitial
<!DOCTYPE html>
<html>
<head>
<title>$3</title>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js?config=TeX-AMS-MML_HTMLorMML"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css">
EndOfMdInitial
if grep -q -E 'class="math( inline)?"' "$2"; then
cat - >>"$2.prefix" <<EndOfMathSupport
${Math1}
${Math2}
${Math3}
EndOfMathSupport
fi
cat - "$2" >>"$2".prefix <<EndOfStyle
${ViewAndStyle}
</head>
<body>
EOF
cat "$2.prefix" - >"$2" <<EOF
EndOfStyle
cat "$2.prefix" - >"$2" <<EndOfTrailer
</body>
</html>
EOF
EndOfTrailer
rm -f "$2".prefix
fi

Expand Down

0 comments on commit 936223b

Please sign in to comment.