gohugoio/hugo · error
invalid strict mode; expected one of error, ignore, or warn;
Error message
invalid strict mode; expected one of error, ignore, or warn; received %s
What it means
`transform.ToMath` renders LaTeX with KaTeX and accepts an options map including `strict`, which controls how KaTeX handles non-standard LaTeX. Hugo validates that `strict` is exactly `error` (the default), `ignore`, or `warn`, and rejects any other value after weak-decoding the options.
Source
Thrown at tpl/transform/transform.go:287
Output: "mathml",
MinRuleThickness: 0.04,
ErrorColor: "#cc0000",
ThrowOnError: true,
Strict: "error",
},
}
if len(args) > 1 {
if err := mapstructure.WeakDecode(args[1], &katexInput.Options); err != nil {
return "", err
}
}
switch katexInput.Options.Strict {
case "error", "ignore", "warn":
// Valid strict mode, continue
default:
return "", fmt.Errorf("invalid strict mode; expected one of error, ignore, or warn; received %s", katexInput.Options.Strict)
}
type fileCacheEntry struct {
Version string `json:"version"`
Output string `json:"output"`
Warnings []string `json:"warnings,omitempty"`
}
const fileCacheEntryVersion = "v1" // Increment on incompatible changes.
s := hashing.HashString(args...)
key := "tomath/" + fileCacheEntryVersion + "/" + s[:2] + "/" + s[2:]
fileCache := ns.deps.ResourceSpec.FileCaches.MiscCache()
v, err := ns.cacheMath.GetOrCreate(key, func(string) (template.HTML, error) {
_, r, err := fileCache.GetOrCreate(key, func() (io.ReadCloser, error) {
message := warpc.Message[warpc.KatexInput]{
Header: warpc.Header{View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Set strict to one of the exact strings: `error`, `ignore`, or `warn`.
- Translate boolean intent: `strict: false` in KaTeX JS ≈ `"ignore"`; `strict: true` ≈ `"error"`.
- Omit the option to keep the default `error` mode.
Example fix
<!-- before -->
{{ transform.ToMath .Inner (dict "strict" false) }}
<!-- after -->
{{ transform.ToMath .Inner (dict "strict" "ignore") }} Defensive patterns
Strategy: validation
Validate before calling
{{ $strict := .Params.strictMode | default "error" }}
{{ if not (in (slice "error" "ignore" "warn") $strict) }}
{{ errorf "strict must be error|ignore|warn, got %q" $strict }}
{{ end }}
{{ $out := transform.ToMath $expr (dict "strict" $strict) }} Prevention
- Only "error", "ignore", or "warn" are valid strict-mode values for transform.ToMath
- Whitelist-validate values coming from front matter or site params
- Keep the value lowercase; don't pass booleans or other types
When it happens
Trigger: Calling `{{ transform.ToMath $expr (dict "strict" "true") }}` or any `strict` value outside error/ignore/warn — e.g. booleans, `"strict"`, `"off"`, or KaTeX-JS function-style values.
Common situations: Assuming `strict` is a boolean like in KaTeX's JS API (where `strict: false` is valid); typos or capitalized values; copying KaTeX docs that use a handler function, which Hugo's embedded KaTeX doesn't accept.
Related errors
- failed to detect format from content
- failed to detect target data serialization format
- invalid options type: %w
- failed to decode options: %w
- invalid character: %q
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/0b294f88d8fda15e.json.
Report an issue: GitHub ↗.