From 7a062a6f5412a3dfd89824045a802f45619e232d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Balv=C3=ADn?= Date: Mon, 28 Sep 2026 13:34:52 +0200 Subject: [PATCH] fix(mathml): render a script without a base over an empty base --- CHANGELOG.md | 1 + internal/mathml/mathml_test.go | 6 ++++++ internal/mathml/parse.go | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d032510..6364617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - A paragraph that follows a definition list, separated from it by a blank line, is no longer swallowed into the `dl` element: the list ends before it, and terms after the paragraph open a list of their own. +- A superscript or subscript without a base, the isotope notation of `^3He`, renders over an empty base instead of degrading to an merror. ### Added diff --git a/internal/mathml/mathml_test.go b/internal/mathml/mathml_test.go index d0bd2e4..8cbc29e 100644 --- a/internal/mathml/mathml_test.go +++ b/internal/mathml/mathml_test.go @@ -37,6 +37,12 @@ var corpus = []struct { {"sqrt", `\sqrt{x}`, `x`}, {"root with index", `\sqrt[3]{x}`, `x3`}, {"sub and sup", `x_1^2`, `x12`}, + {"baseless sup", `^3\mathrm{He}`, + `3He`}, + {"baseless sub", `_1\mathrm{H}`, + `1H`}, + {"baseless group", `^{-3}`, + `-3`}, {"single digit script", `x^10`, `x10`}, {"group", `{xy}`, `xy`}, {"left right", `\left( x \right)`, diff --git a/internal/mathml/parse.go b/internal/mathml/parse.go index f86e198..29f364e 100644 --- a/internal/mathml/parse.go +++ b/internal/mathml/parse.go @@ -128,6 +128,12 @@ func (p *parser) atom() *node { return nil } return p.scripts(n) + case tokCaret, tokUnderscore: + // A script without a base, the isotope notation of ^3He, takes + // an empty base: the script renders over nothing, the way the + // notation is printed, and degrading it would refuse notation + // the mathematics carries. + return p.scripts(el("mrow")) } p.pos++ return errorNode(t.text)