From bc16341ca1e7c05b1f820554ca75b6c552aa4b56 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Thu, 13 Feb 2025 14:46:13 -0800 Subject: [PATCH] theme: Render mathematical markup with transform.ToMath Closes #2897 --- content/en/content-management/mathematics.md | 4 ++++ layouts/_default/_markup/render-passthrough.html | 9 +++++++++ layouts/_default/baseof.html | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 layouts/_default/_markup/render-passthrough.html diff --git a/content/en/content-management/mathematics.md b/content/en/content-management/mathematics.md index aa398d334..0006de29d 100644 --- a/content/en/content-management/mathematics.md +++ b/content/en/content-management/mathematics.md @@ -230,6 +230,8 @@ To use KaTeX instead of MathJax, replace the partial template from [Step 2] with The delimiters above must match the delimiters in your site configuration. + + [KaTeX]: https://katex.org/ [LaTeX]: https://www.latex-project.org/ [MathJax]: https://www.mathjax.org/ diff --git a/layouts/_default/_markup/render-passthrough.html b/layouts/_default/_markup/render-passthrough.html new file mode 100644 index 000000000..0ed001133 --- /dev/null +++ b/layouts/_default/_markup/render-passthrough.html @@ -0,0 +1,9 @@ +{{- $opts := dict "output" "htmlAndMathml" "displayMode" (eq .Type "block") }} +{{- with try (transform.ToMath .Inner $opts) }} + {{- with .Err }} + {{ errorf "Unable to render mathematical markup to HTML using the transform.ToMath function. The KaTeX display engine threw the following error: %s: see %s." . $.Position }} + {{- else }} + {{- .Value }} + {{- $.Page.Store.Set "hasMath" true }} + {{- end }} +{{- end -}} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index f6e281455..4481b96f9 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -34,6 +34,10 @@ {{ end }} {{ $t.Stop }} {{ end }} + {{ $noop := .WordCount }} + {{ if .Page.Store.Get "hasMath" }} + + {{ end }} {{ partial "layouts/head/head.html" . }}