Skip to content

Commit

Permalink
feat(math): Support MathML maction (basic) and mstyle (partial)
Browse files Browse the repository at this point in the history
Legit MathML elements for which a naive implementation is better than
nothing and paves the way to check other more important elements from
the MathML test suite.
  • Loading branch information
Omikhleia authored and Didier Willis committed Nov 2, 2024
1 parent 9ce5271 commit 0df93b1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/math/typesetter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ local function convertChildren (tree)
return mboxes
end

local function convertFirstChild (tree)
-- We need to loop until the first non-nil box is found, because
-- we may have blank lines in the tree.
for _, n in ipairs(tree) do
local box = ConvertMathML(nil, n)
if box then
return box
end
end
end

-- convert MathML into mbox
function ConvertMathML (_, content)
if content == nil or content.command == nil then
Expand Down Expand Up @@ -159,6 +170,13 @@ function ConvertMathML (_, content)
-- There's also some explanations about CSS, italic correction etc. which we ignore too.
text = text:gsub("[\n\r]", " ")
return b.text("string", {}, scriptType.upright, text:gsub("%s+", " "))
elseif content.command == "maction" then
-- MathML Core 3.6: display as mrow, ignoring all but the first child
return b.stackbox("H", { convertFirstChild(content) })
elseif content.command == "mstyle" then
-- It's an mrow, but with some style attributes that we ignore.
SU.warn("MathML mstyle is not fully supported yet")
return b.stackbox("H", convertChildren(content))
else
SU.error("Unknown math command " .. content.command)
end
Expand Down

0 comments on commit 0df93b1

Please sign in to comment.