Skip to content

Commit a60c989

Browse files
committed
feat(math): Support MathML mathcolor and mathbackground attributes
1 parent 6752017 commit a60c989

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/math/base-elements.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,37 @@ end
268268

269269
-- Output the node and all its descendants
270270
function elements.mbox:outputTree (x, y, line)
271+
-- MathML 4.0 Draft 23 October 2025 §3.1.9.1 for mathcolor and mathbackground
272+
if self.attributes.mathbackground then
273+
local color = SILE.types.color(self.attributes.mathbackground)
274+
local xs = scaleWidth(x, line)
275+
local ws = scaleWidth(self.width, line)
276+
local h = self.height.length
277+
local d = self.depth.length
278+
SILE.outputter:pushColor(color)
279+
SILE.outputter:drawRule(xs, y - h, ws, h + d)
280+
SILE.outputter:popColor()
281+
end
282+
if self.attributes.mathcolor then
283+
local color = SILE.types.color(self.attributes.mathcolor)
284+
SILE.outputter:pushColor(color)
285+
end
286+
271287
self:output(x, y, line)
272288
local debug = SILE.settings:get("math.debug.boxes")
273289
if debug and not (self:is_a(elements.space)) then
274-
SILE.outputter:setCursor(scaleWidth(x, line), y.length)
275-
SILE.outputter:debugHbox({ height = self.height.length, depth = self.depth.length }, scaleWidth(self.width, line))
290+
SILE.outputter:setCursor(xs, y.length)
291+
SILE.outputter:debugHbox({ height = self.height.length, depth = self.depth.length }, xs)
276292
end
277293
for _, n in ipairs(self.children) do
278294
if n then
279295
n:outputTree(x + n.relX, y + n.relY, line)
280296
end
281297
end
298+
299+
if self.attributes.mathcolor then
300+
SILE.outputter:popColor()
301+
end
282302
end
283303

284304
local spaceKind = {

0 commit comments

Comments
 (0)