From 891aa00fe14101feed2fab4b6c79ea35773c9fe0 Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Sun, 11 Aug 2024 15:25:10 +0200 Subject: Add some more KaTeX options And fix the options handling. Closes #12745 Fixes #12746 --- internal/warpc/katex.go | 26 +++++++++++++++++++++++--- tpl/transform/transform.go | 7 ++++--- tpl/transform/transform_integration_test.go | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/internal/warpc/katex.go b/internal/warpc/katex.go index 0a85d94b6..2412467a9 100644 --- a/internal/warpc/katex.go +++ b/internal/warpc/katex.go @@ -13,10 +13,30 @@ type KatexInput struct { Options KatexOptions `json:"options"` } +// KatexOptions defines the options for the KaTeX rendering. +// See https://katex.org/docs/options.html type KatexOptions struct { - Output string `json:"output"` // html, mathml (default), htmlAndMathml - DisplayMode bool `json:"displayMode"` - ThrowOnError bool `json:"throwOnError"` + // html, mathml (default), htmlAndMathml + Output string `json:"output"` + + // If true, display math in display mode, false in inline mode. + DisplayMode bool `json:"displayMode"` + + // Render \tags on the left side instead of the right. + Leqno bool `json:"leqno"` + + // If true, render flush left with a 2em left margin. + Fleqn bool `json:"fleqn"` + + // The color used for typesetting errors. + // A color string given in the format "#XXX" or "#XXXXXX" + ErrorColor string `json:"errorColor"` + + // A collection of custom macros. + Macros map[string]string `json:"macros,omitempty"` + + // Specifies a minimum thickness, in ems, for fraction lines. + MinRuleThickness float64 `json:"minRuleThickness"` } type KatexOutput struct { 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'] y + `) +} -- cgit v1.2.3