aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-08-11 15:25:10 +0200
committerBjørn Erik Pedersen <[email protected]>2024-08-11 19:03:27 +0200
commit891aa00fe14101feed2fab4b6c79ea35773c9fe0 (patch)
tree1138402232bb929988b12e467b6a33e1bac3ccd9 /tpl
parent946e6af0bb662861c954ccff60b2861aa5e1166e (diff)
downloadhugo-891aa00fe14101feed2fab4b6c79ea35773c9fe0.tar.gz
hugo-891aa00fe14101feed2fab4b6c79ea35773c9fe0.zip
Add some more KaTeX options
And fix the options handling. Closes #12745 Fixes #12746
Diffstat (limited to 'tpl')
-rw-r--r--tpl/transform/transform.go7
-rw-r--r--tpl/transform/transform_integration_test.go21
2 files changed, 25 insertions, 3 deletions
diff --git a/tpl/transform/transform.go b/tpl/transform/transform.go
index 10a91671d..bcec9346b 100644
--- a/tpl/transform/transform.go
+++ b/tpl/transform/transform.go
@@ -211,13 +211,14 @@ func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, er
katexInput := warpc.KatexInput{
Expression: expression,
Options: warpc.KatexOptions{
- Output: "mathml",
- ThrowOnError: false,
+ Output: "mathml",
+ MinRuleThickness: 0.04,
+ ErrorColor: "#cc0000",
},
}
if len(args) > 1 {
- if err := mapstructure.WeakDecode(args[1], &katexInput); err != nil {
+ if err := mapstructure.WeakDecode(args[1], &katexInput.Options); err != nil {
return "", err
}
}
diff --git a/tpl/transform/transform_integration_test.go b/tpl/transform/transform_integration_test.go
index b030417a2..9e5221c9a 100644
--- a/tpl/transform/transform_integration_test.go
+++ b/tpl/transform/transform_integration_test.go
@@ -149,3 +149,24 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term']
<span class="katex"><math
`)
}
+
+func TestToMathMacros(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+-- layouts/index.html --
+{{ $macros := dict
+ "\\addBar" "\\bar{#1}"
+ "\\bold" "\\mathbf{#1}"
+}}
+{{ $opts := dict "macros" $macros }}
+{{ transform.ToMath "\\addBar{y} + \\bold{H}" $opts }}
+ `
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/index.html", `
+<mi>y</mi>
+ `)
+}