Skip to content

Commit bde46cd

Browse files
Omikhleiaalerque
authored andcommitted
fix(math): Honor stretchy attribute on MathML mo elements
And also override other explicit attributes from the element over those from the default operator table.
1 parent 7c58886 commit bde46cd

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

packages/math/base-elements.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function elements.stackbox:shape ()
423423
end
424424
-- Handle stretchy operators
425425
for _, elt in ipairs(self.children) do
426-
if elt.is_a(elements.text) and elt.kind == "operator" and elt.stretchy then
426+
if elt.is_a(elements.text) and elt.kind == "operator" and SU.boolean(elt.stretchy, false) then
427427
elt:_vertStretchyReshape(self.depth, self.height)
428428
end
429429
end
@@ -554,7 +554,7 @@ function elements.subscript:shape ()
554554
local subShift
555555
local supShift
556556
if self.sub then
557-
if self.isUnderOver or self.base.largeop then
557+
if self.isUnderOver or SU.boolean(self.base.largeop, false) then
558558
-- Ad hoc correction on integral limits, following LuaTeX's
559559
-- `\mathnolimitsmode=0` (see LuaTeX Reference Manual).
560560
subShift = -itCorr
@@ -567,12 +567,12 @@ function elements.subscript:shape ()
567567
--self.base.depth + constants.subscriptBaselineDropMin * scaleDown,
568568
(self.sub.height - constants.subscriptTopMax * scaleDown):tonumber()
569569
))
570-
if self:is_a(elements.underOver) or self:is_a(elements.stackbox) or self.base.largeop then
570+
if self:is_a(elements.underOver) or self:is_a(elements.stackbox) or SU.boolean(self.base.largeop, false) then
571571
self.sub.relY = maxLength(self.sub.relY, self.base.depth + constants.subscriptBaselineDropMin * scaleDown)
572572
end
573573
end
574574
if self.sup then
575-
if self.isUnderOver or self.base.largeop then
575+
if self.isUnderOver or SU.boolean(self.base.largeop, false) then
576576
-- Ad hoc correction on integral limits, following LuaTeX's
577577
-- `\mathnolimitsmode=0` (see LuaTeX Reference Manual).
578578
supShift = 0
@@ -586,7 +586,7 @@ function elements.subscript:shape ()
586586
--self.base.height - constants.superscriptBaselineDropMax * scaleDown,
587587
(self.sup.depth + constants.superscriptBottomMin * scaleDown):tonumber()
588588
)) * -1
589-
if self:is_a(elements.underOver) or self:is_a(elements.stackbox) or self.base.largeop then
589+
if self:is_a(elements.underOver) or self:is_a(elements.stackbox) or SU.boolean(self.base.largeop, false) then
590590
self.sup.relY = maxLength(
591591
(0 - self.sup.relY),
592592
self.base.height - constants.superscriptBaselineDropMax * scaleDown
@@ -663,9 +663,9 @@ function elements.underOver:styleChildren ()
663663
end
664664

665665
function elements.underOver:shape ()
666-
if not (self.mode == mathMode.display or self.mode == mathMode.displayCramped) and self.base.largeop then
666+
if not (self.mode == mathMode.display or self.mode == mathMode.displayCramped) and SU.boolean(self.base.largeop, false) then
667667
-- FIXME
668-
-- Added the self.base.largeop condition, but it's kind of a workaround:
668+
-- Added the "largeop" condition, but it's kind of a workaround:
669669
-- It should rather be the "moveablelimits" propery in MathML, but we do not have that yet.
670670
-- When the base is a moveable limit, the under/over scripts are not placed under/over the base,
671671
-- but ather to the right of it, when display mode is not used.
@@ -861,8 +861,8 @@ function elements.text:__tostring ()
861861
.. tostring(self.kind)
862862
.. ", script="
863863
.. tostring(self.script)
864-
.. (self.stretchy and ", stretchy" or "")
865-
.. (self.largeop and ", largeop" or "")
864+
.. (SU.boolean(self.stretchy, false) and ", stretchy" or "")
865+
.. (SU.boolean(self.largeop, false) and ", largeop" or "")
866866
.. ', text="'
867867
.. (self.originalText or self.text)
868868
.. '")'
@@ -897,7 +897,7 @@ function elements.text:shape ()
897897
local mathMetrics = self:getMathMetrics()
898898
local glyphs = SILE.shaper:shapeToken(self.text, self.font)
899899
-- Use bigger variants for big operators in display style
900-
if isDisplayMode(self.mode) and self.largeop then
900+
if isDisplayMode(self.mode) and SU.boolean(self.largeop, false) then
901901
-- We copy the glyph list to avoid modifying the shaper's cache. Yes.
902902
glyphs = pl.tablex.deepcopy(glyphs)
903903
local constructions = mathMetrics.mathVariants.vertGlyphConstructions[glyphs[1].gid]

packages/math/typesetter.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,16 @@ function ConvertMathML (_, content)
7272
or scriptType.upright
7373
local text = content[1]
7474
local attributes = {}
75+
-- Attributes from the (default) oerator table
7576
if syms.symbolDefaults[text] then
7677
for attribute, value in pairs(syms.symbolDefaults[text]) do
7778
attributes[attribute] = value
7879
end
7980
end
81+
-- Overwrite with attributes from the element
82+
for attribute, value in pairs(content.options) do
83+
attributes[attribute] = value
84+
end
8085
if content.options.atom then
8186
if not atomTypeShort[content.options.atom] then
8287
SU.error("Unknown atom type " .. content.options.atom)

0 commit comments

Comments
 (0)