mathext

package
v0.0.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mathext is a goldmark extension that recognises TeX math written between dollar delimiters and renders it as MathML. Inline math uses single dollars ($…$), display math uses double dollars ($$…$$). The actual TeX→MathML conversion is delegated to the texmath package; this package only owns the Markdown-level concerns: where a formula starts and ends, and how it serialises into the HTML stream that htmlbag consumes.

Running as a real goldmark inline parser (rather than a regex pre-pass) buys two things for free: dollars inside `code spans` and fenced code blocks are never treated as math, and the strict opening/closing rules below disambiguate prose dollars ("it costs $5 and $6") from formulas — the same convention Pandoc uses and PLOS expects for Markdown submissions.

Index

Constants

This section is empty.

Variables

View Source
var KindMathInline = ast.NewNodeKind("MathInline")

KindMathInline is the AST node kind for a parsed math span.

View Source
var Math = &Extension{}

Math is the ready-to-use extension instance.

Functions

This section is empty.

Types

type Extension

type Extension struct{}

Extension is the goldmark extender. Add it to goldmark.New via goldmark.WithExtensions(mathext.Math).

func (*Extension) Extend

func (e *Extension) Extend(m goldmark.Markdown)

Extend registers the dollar-math inline parser and its MathML renderer.

type MathInline

type MathInline struct {
	ast.BaseInline
	Source  []byte
	Display bool
}

MathInline is the AST node a math span parses into. Source is the raw TeX between the delimiters; Display selects $$…$$ (block) over $…$ (inline).

func (*MathInline) Dump

func (n *MathInline) Dump(source []byte, level int)

Dump implements ast.Node for debugging.

func (*MathInline) Kind

func (n *MathInline) Kind() ast.NodeKind

Kind implements ast.Node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL