mathml

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0, MIT Imports: 13 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mathml converts between Untie canonical IR and Presentation MathML.

Marshal and Write cover every canonical IR node family. Unmarshal is a deliberately smaller, strict importer: it accepts the documented subset in docs/mathml.md and rejects unknown elements, attributes, and semantic values with structured diagnostics.

MathML is an interchange boundary, not a renderer shortcut. Source spans, text-cluster maps, and dialect syntax cannot be represented soundly in Presentation MathML and are never invented by the importer.

Index

Constants

View Source
const (
	// Namespace is the Presentation MathML XML namespace.
	Namespace = "http://www.w3.org/1998/Math/MathML"

	// SchemaVersion identifies Untie's optional MathML metadata conventions.
	// It is emitted as data-untie-version on the root math element.
	SchemaVersion = 1

	// DefaultMaxOutputBytes bounds all output produced by Marshal and Write.
	DefaultMaxOutputBytes = 16 << 20
)

Variables

View Source
var (
	// ErrInvalidContext reports a nil context.
	ErrInvalidContext = errors.New("mathml: nil context")
	// ErrInvalidFormula reports malformed Untie input or an invalid export mode.
	ErrInvalidFormula = errors.New("mathml: invalid formula")
	// ErrInvalidMathML reports malformed or structurally invalid MathML input.
	ErrInvalidMathML = errors.New("mathml: invalid MathML")
	// ErrUnsupported reports valid-looking MathML outside the documented subset.
	ErrUnsupported = errors.New("mathml: unsupported construct")
	// ErrLimitExceeded reports an input, traversal, or output limit.
	ErrLimitExceeded = errors.New("mathml: limit exceeded")
)

Functions

func Marshal

func Marshal(ctx context.Context, f *ir.Formula, mode ir.Mode, options Options) ([]byte, error)

Marshal returns deterministic Presentation MathML for f.

func Write

func Write(ctx context.Context, out io.Writer, f *ir.Formula, mode ir.Mode, options Options) error

Write emits deterministic Presentation MathML to out.

The formula is validated before any bytes are written. Write may have produced a prefix when it later returns a context, writer, or output-limit error; callers that require atomic output should use Marshal.

Types

type Options

type Options struct {
	// Limits bounds formula validation, input traversal, and generated
	// accessibility text.
	Limits source.Limits

	// MaxOutputBytes bounds Marshal and Write output. Import input is bounded
	// by Limits.MaxSourceBytes.
	MaxOutputBytes int
}

Options controls one MathML operation. Zero fields select defaults.

type Result

type Result struct {
	Formula     *ir.Formula
	Mode        ir.Mode
	Diagnostics []source.Diagnostic
}

Result is the strict importer result.

Formula is non-nil only when Diagnostics is empty and err is nil. Mode is meaningful whenever Formula is non-nil. Diagnostic ranges address the input MathML bytes; imported IR nodes always use detached source ranges.

func Unmarshal

func Unmarshal(ctx context.Context, data []byte, options Options) (Result, error)

Unmarshal parses a bounded Presentation MathML subset into validated canonical IR.

Malformed or unsupported input returns a Result containing deterministic diagnostics and a matching sentinel error. Context cancellation always returns the context error and takes precedence over input diagnostics.

func UnmarshalString

func UnmarshalString(ctx context.Context, text string, options Options) (Result, error)

UnmarshalString is Unmarshal for a string input.

Jump to

Keyboard shortcuts

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