fix(hugo): preserve $...$ inline math through Goldmark passthrough - #63
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #62
Problem
Inline math written as
$x+x$was not being rendered by MathJax inthe Relearn theme, while display math
$$x+x$$rendered fine.Root cause
The Goldmark
passthroughextension is what preserves math delimitersthrough markdown parsing and hands them to MathJax. In
internal/hugo/models/config.go,EnableMathPassthroughconfiguredonly
\\(...\\)as the inline delimiter set.$...$was not inthe list, so Goldmark treated it as ordinary text and stripped/rewrote
it during rendering.
Fix
Add
{"$", "$"}to the inline delimiters inEnableMathPassthrough, alongside the existing\\(...\\)pair.Both conventional inline-math forms now pass through to MathJax.
Display math delimiters (
$$...$$,\\[...\\]) are unchangedand were already working.
Trade-off: escaping literal
$With
$...$recognised as math, any paired$characters inprose 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:This is documented in
docs/how-to/use-relearn-theme.md(new"Math Support" section).
Verification
go test ./...— all packages passgolangci-lint run ./...— 0 issuesgo vet ./internal/hugo/...— cleango build ./...— cleanreflect the new inline delimiter pair