gohugoio/hugo · error

must provide at least one argument

Error message

must provide at least one argument

What it means

Thrown by transform.ToMath when no argument is supplied (tpl/transform/transform.go:258-259). ToMath requires at least a LaTeX expression string; it renders math to MathML via KaTeX.

Source

Thrown at tpl/transform/transform.go:259

// We may add more options in the future.
func (ns *Namespace) PortableText(v any) (string, error) {
	buf := bp.GetBuffer()
	defer bp.PutBuffer(buf)
	opts := goportabletext.ToMarkdownOptions{
		Dst: buf,
		Src: v,
	}
	if err := goportabletext.ToMarkdown(opts); err != nil {
		return "", err
	}
	return buf.String(), nil
}

// ToMath converts a LaTeX string to math in the given format, default MathML.
// This uses KaTeX to render the math, see https://katex.org/.
func (ns *Namespace) ToMath(ctx context.Context, args ...any) (template.HTML, error) {
	if len(args) < 1 {
		return "", errors.New("must provide at least one argument")
	}
	expression, err := cast.ToStringE(args[0])
	if err != nil {
		return "", err
	}

	katexInput := warpc.KatexInput{
		Expression: expression,
		Options: warpc.KatexOptions{
			Output:           "mathml",
			MinRuleThickness: 0.04,
			ErrorColor:       "#cc0000",
			ThrowOnError:     true,
			Strict:           "error",
		},
	}

	if len(args) > 1 {

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Always pass the expression: {{ transform.ToMath "e^{i\\pi}+1=0" }}.
  2. Guard against empty input: {{ with .Expr }}{{ transform.ToMath . }}{{ end }}.

Example fix

// before
{{ transform.ToMath }}
// after
{{ transform.ToMath "\\frac{a}{b}" }}
Defensive patterns

Strategy: validation

Validate before calling

{{ with .Expr }}{{ transform.ToMath . }}{{ end }}

Prevention

When it happens

Trigger: Calling {{ transform.ToMath }} with no arguments, or piping nothing into it.

Common situations: Forgetting the expression; using a partial that doesn't forward the expression; conditionally rendering a math block where the value is absent.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/f2834ae5a1cb7a6a. Report an issue: GitHub.