diff --git a/packages/math/texlike.lua b/packages/math/texlike.lua index f2cd799f9..e9b25ae27 100644 --- a/packages/math/texlike.lua +++ b/packages/math/texlike.lua @@ -261,6 +261,9 @@ local compileToStr = function (argEnv, mathlist) end local function isOperatorKind (tree, typeOfAtom, typeOfSymbol) + if not tree then + return false -- safeguard + end if tree.command ~= "mo" then return false end @@ -363,6 +366,22 @@ local function compileToMathML_aux (_, arg_env, tree) if #stack > 0 then children = table.remove(stack) end + elseif (child.command == "msubsup" or child.command == "msub" or child.command == "msup") + and isCloseOperator(child[1]) -- child[1] is the base + then + if #stack > 0 then + -- Special case for closing operator with sub/superscript: + -- (....)^i must be interpreted as {(....)}^i, not as (...{)}^i + -- Push the closing operator into the mrow + table.insert(children, child[1]) + -- Move the mrow into the msubsup, replacing the closing operator + child[1] = children + -- And insert the msubsup into the parent + children = table.remove(stack) + children[#children] = child + else + table.insert(children, child) + end else table.insert(children, child) end