Skip to content

fix(hugo): preserve $...$ inline math through Goldmark passthrough - #63

Merged
inful merged 3 commits into
mainfrom
fix/issue-62-inline-math
Jun 12, 2026
Merged

fix(hugo): preserve $...$ inline math through Goldmark passthrough#63
inful merged 3 commits into
mainfrom
fix/issue-62-inline-math

Conversation

@inful

@inful inful commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Closes #62

Problem

Inline math written as $x+x$ was not being rendered by MathJax in
the Relearn theme, while display math $$x+x$$ rendered fine.

Root cause

The Goldmark passthrough extension is what preserves math delimiters
through markdown parsing and hands them to MathJax. In
internal/hugo/models/config.go, EnableMathPassthrough configured
only \\(...\\) as the inline delimiter set. $...$ was not in
the list, so Goldmark treated it as ordinary text and stripped/rewrote
it during rendering.

Fix

Add {"$", "$"} to the inline delimiters in
EnableMathPassthrough, alongside the existing \\(...\\) pair.
Both conventional inline-math forms now pass through to MathJax.
Display math delimiters ($$...$$, \\[...\\]) are unchanged
and were already working.

Trade-off: escaping literal $

With $...$ recognised as math, any paired $ characters in
prose will be treated as a math span. This is the same convention
KaTeX, MathJax and Pandoc use. Content with currency, shell variables,
or any other literal $ must escape with `\$. For example:

It costs \$5 and \$10.
Use \$HOME or \$TMPDIR for paths.

This is documented in docs/how-to/use-relearn-theme.md (new
"Math Support" section).

Verification

  • go test ./... — all packages pass
  • golangci-lint run ./... — 0 issues
  • go vet ./internal/hugo/... — clean
  • go build ./... — clean
  • 18 golden test fixtures + 2 hugo_config testdata fixtures updated to
    reflect the new inline delimiter pair

inful added 3 commits June 12, 2026 13:55
Inline math written as $x+x$ was being stripped or re-rendered
instead of handed to MathJax, because the Goldmark passthrough
extension's inline delimiters only included \\(...\\).

Add the standard $...$ pair alongside the existing delimiters, so
both conventional inline-math forms pass through to MathJax. Display
math ($$...$$ and \\[...\\]) is unaffected and was already
working.

Closes #62
Adding $...$ as an inline math delimiter (the previous commit) means
any paired $ in prose is now treated as math. Document the supported
delimiter forms and the escape rule for literal $ characters, since
this is inherent to the standard math delimiter convention and not a
docbuilder-specific quirk.
@inful
inful merged commit 75413a9 into main Jun 12, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline math does not work

1 participant