Files
FixIt/layouts/_markup/render-passthrough.html
T
Cell 0ce74d82f8 ♻️ Refactor: mathematical formula render (#609)
*  Feat: add support for math passthrough render hook

*  Feat: enable copy-tex extension for KaTeX server-side render

*  Feat: enhance mathematical rendering support with KaTeX and MathJax configurations

*  Feat: add KaTeX error handling and custom macros map config

*  Feat: add MathJax client-side rendering as an alternative math engine

*  Feat: update MathJax CDN configuration and enhance asset loading parameters

* 🔥 Feat: remove unused KaTeX math rendering scripts and update KaTex

*  Feat: make \KaTeX command work in MathJax

*  Feat: update KaTeX CDN links for Twikoo integration

*  Perf: Math in content encryption

* 🐛 Fix: update class name from 'fi-row' to 'fi-raw' in raw.html shortcode

* 🐛 Fix: correct MathJax math delimiters in load-mathjax.js

*  Feat: enhance MathJax configuration with additional tex parameters and update asset handling

* 🐛 Fix: adjust KaTeX display overflow behavior
2025-06-30 12:58:48 +08:00

46 lines
1.6 KiB
HTML

{{- $params := .Page.Params | merge site.Params.page -}}
{{- $math := $params.math -}}
{{- if eq $math true -}}
{{- $math = dict "enable" true | merge site.Params.page.math -}}
{{- else if eq $math false -}}
{{- $math = dict "enable" false -}}
{{- end -}}
{{- /*
Mathematical formulas rendering:
- KaTeX server-side rendering
- MathJax client-side rendering
Regular passthrough rendering:
- [todo] support more features in future
*/ -}}
{{- if $math.enable -}}
{{- if eq $math.type "katex" -}}
{{- $katex := $math.katex -}}
{{- $opts := dict "output" "htmlAndMathml" "displayMode" (eq $.Type "block") }}
{{- $opts = dict "throwOnError" $katex.throwOnError "errorColor" $katex.errorColor | merge $opts }}
{{- $macros := $katex.macros | default dict -}}
{{- if $macros -}}
{{- $opts = dict "macros" $macros | merge $opts -}}
{{- end -}}
{{- /* render mathematical markup to HTML */ -}}
{{- 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 "hasKaTeX" true -}}
{{- end }}
{{- end -}}
{{- else if eq $math.type "mathjax" -}}
{{- if eq $.Type "block" -}}
$${{- .Inner -}}$$
{{- else -}}
${{ .Inner }}$
{{- end -}}
{{- end -}}
{{- else -}}
{{- /* Regular passthrough rendering */ -}}
{{- /* waiting for Hugo interface to get delimiters */ -}}
{{- .Inner -}}
{{- end -}}