Skip to content

Commit 92c678a

Browse files
OmikhleiaDidier Willis
authored andcommitted
feat(math): Support MathML movablelimits attribute
1 parent 626fe7a commit 92c678a

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

packages/math/base-elements.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,17 +718,13 @@ function elements.underOver:_stretchyReshapeToBase (part)
718718
end
719719

720720
function elements.underOver:shape ()
721-
local isBaseLargeOp = SU.boolean(self.base and self.base.largeop, false)
722-
if not (self.mode == mathMode.display or self.mode == mathMode.displayCramped) and isBaseLargeOp then
723-
-- FIXME
724-
-- Added the "largeop" condition, but it's kind of a workaround:
725-
-- It should rather be the "moveablelimits" property in MathML, but we do not have that yet.
726-
-- When the base is a moveable limit, the under/over scripts are not placed under/over the base,
721+
local isMovableLimits = SU.boolean(self.base and self.base.movablelimits, false)
722+
if not (self.mode == mathMode.display or self.mode == mathMode.displayCramped) and isMovableLimits then
723+
-- When the base is a movable limit, the under/over scripts are not placed under/over the base,
727724
-- but other to the right of it, when display mode is not used.
728725
-- Notable effects:
729726
-- Mozilla MathML test 19 (on "k times" > overbrace > base)
730727
-- Maxwell's Equations in MathML3 Test Suite "complex1" (on the vectors in fractions)
731-
-- For now, go with the "largeop" property, but this is not correct.
732728
self.isUnderOver = true
733729
elements.subscript.shape(self)
734730
return

packages/math/texlike.lua

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,17 @@ local function isOperatorKind (tree, typeOfAtom, typeOfSymbol)
280280
return false
281281
end
282282

283-
local function isBigOperator (tree)
284-
return isOperatorKind(tree, "big", atomType.bigOperator)
283+
local function isMoveableLimits (tree)
284+
if tree.command ~= "mo" then
285+
return false
286+
end
287+
if tree.options and SU.boolean(tree.options.movablelimits, false) then
288+
return true
289+
end
290+
if tree[1] and symbolDefaults[tree[1]] and SU.boolean(symbolDefaults[tree[1]].movablelimits, false) then
291+
return true
292+
end
293+
return false
285294
end
286295
local function isCloseOperator (tree)
287296
return isOperatorKind(tree, "close", atomType.closeSymbol)
@@ -414,13 +423,13 @@ local function compileToMathML_aux (_, arg_env, tree)
414423
tree.options = {}
415424
-- Translate TeX-like sub/superscripts to `munderover` or `msubsup`,
416425
-- depending on whether the base is a big operator
417-
elseif tree.id == "sup" and isBigOperator(tree[1]) then
426+
elseif tree.id == "sup" and isMoveableLimits(tree[1]) then
418427
tree.command = "mover"
419-
elseif tree.id == "sub" and isBigOperator(tree[1]) then
428+
elseif tree.id == "sub" and isMoveableLimits(tree[1]) then
420429
tree.command = "munder"
421-
elseif tree.id == "subsup" and isBigOperator(tree[1]) then
430+
elseif tree.id == "subsup" and isMoveableLimits(tree[1]) then
422431
tree.command = "munderover"
423-
elseif tree.id == "supsub" and isBigOperator(tree[1]) then
432+
elseif tree.id == "supsub" and isMoveableLimits(tree[1]) then
424433
tree.command = "munderover"
425434
local tmp = tree[2]
426435
tree[2] = tree[3]
@@ -589,20 +598,20 @@ compileToMathML(
589598
\def{bi}{\mi[mathvariant=bold-italic]{#1}}
590599
\def{dsi}{\mi[mathvariant=double-struck]{#1}}
591600
592-
\def{lim}{\mo[atom=big]{lim}}
601+
\def{lim}{\mo[movablelimits=true]{lim}}
593602
594603
% From amsmath:
595604
\def{to}{\mo[atom=bin]{→}}
596-
\def{gcd}{\mo[atom=big]{gcd}}
597-
\def{sup}{\mo[atom=big]{sup}}
598-
\def{inf}{\mo[atom=big]{inf}}
599-
\def{max}{\mo[atom=big]{max}}
600-
\def{min}{\mo[atom=big]{min}}
605+
\def{gcd}{\mo[movablelimits=true]{gcd}}
606+
\def{sup}{\mo[movablelimits=true]{sup}}
607+
\def{inf}{\mo[movablelimits=true]{inf}}
608+
\def{max}{\mo[movablelimits=true]{max}}
609+
\def{min}{\mo[movablelimits=true]{min}}
601610
% Those use U+202F NARROW NO-BREAK SPACE in their names
602-
\def{limsup}{\mo[atom=big]{lim sup}}
603-
\def{liminf}{\mo[atom=big]{lim inf}}
604-
\def{projlim}{\mo[atom=big]{proj lim}}
605-
\def{injlim}{\mo[atom=big]{inj lim}}
611+
\def{limsup}{\mo[movablelimits=true]{lim sup}}
612+
\def{liminf}{\mo[movablelimits=true]{lim inf}}
613+
\def{projlim}{\mo[movablelimits=true]{proj lim}}
614+
\def{injlim}{\mo[movablelimits=true]{inj lim}}
606615
607616
% Standard spaces gleaned from plain TeX
608617
\def{thinspace}{\mspace[width=thin]}

packages/math/unicode-symbols.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,14 +2628,14 @@ symbolDefaults["="] = { atom = atomType.relationalOperator }
26282628
symbolDefaults[""] = { atom = atomType.relationalOperator }
26292629
symbolDefaults[""] = { atom = atomType.relationalOperator }
26302630
symbolDefaults[""] = { atom = atomType.relationalOperator }
2631-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2632-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2633-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2634-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2635-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2636-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2637-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2638-
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true }
2631+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
2632+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
2633+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
2634+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
2635+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
2636+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
2637+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
2638+
symbolDefaults[""] = { atom = atomType.bigOperator, largeop = true, movablelimits = true }
26392639
symbolDefaults[""] = { largeop = true }
26402640
symbolDefaults[""] = { largeop = true }
26412641
symbolDefaults[""] = { largeop = true }

0 commit comments

Comments
 (0)