Skip to content

Instantly share code, notes, and snippets.

@unennhexium
Last active June 2, 2024 17:24
Show Gist options
  • Save unennhexium/2b4a352d51b8423e30ef09263b0dc2f0 to your computer and use it in GitHub Desktop.
Save unennhexium/2b4a352d51b8423e30ef09263b0dc2f0 to your computer and use it in GitHub Desktop.
Hugo Blowfish theme: adding custom delimiters to render math inside
[goldmark]
[goldmark.renderer]
unsafe = true
[goldmark.extensions.passthrough]
enable = true
delimiters.block = [["\\[", "\\]"], ["$$", "$$"]]
delimiters.inline = [["\\(", "\\)"], ["$", "$"]]
Index: themes/blowfish/layouts/partials/vendor.html
<+>UTF-8
===================================================================
diff --git a/themes/blowfish/layouts/partials/vendor.html b/themes/blowfish/layouts/partials/vendor.html
--- a/themes/blowfish/layouts/partials/vendor.html
+++ b/themes/blowfish/layouts/partials/vendor.html (date 1717343639599)
@@ -36,8 +36,23 @@
<script defer src="{{ $katexJS.RelPermalink }}" integrity="{{ $katexJS.Data.Integrity }}"></script>
{{ $katexRenderJS := resources.Get "lib/katex/auto-render.min.js" }}
{{ $katexRenderJS := $katexRenderJS | resources.Fingerprint "sha512" }}
-<script defer src="{{ $katexRenderJS.RelPermalink }}" integrity="{{ $katexRenderJS.Data.Integrity }}"
- onload="renderMathInElement(document.body);"></script>
+<script defer src="{{ $katexRenderJS.RelPermalink }}" integrity="{{ $katexRenderJS.Data.Integrity }}"></script>
+<script>
+ document.addEventListener("DOMContentLoaded", function() {
+ renderMathInElement(document.body, {
+ // customised options
+ // • auto-render specific keys, e.g.:
+ delimiters: [
+ {left: '$$', right: '$$', display: true},
+ {left: '$', right: '$', display: false},
+ {left: '\\(', right: '\\)', display: false},
+ {left: '\\[', right: '\\]', display: true}
+ ],
+ // • rendering keys, e.g.:
+ throwOnError : false
+ });
+ });
+</script>
{{ $katexFonts := resources.Match "lib/katex/fonts/*" }}
{{ range $katexFonts }}
<!-- {{ .RelPermalink }} -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment