From 48b7c2ca9df1ce470cb6245bc55852d53b89807c Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Tue, 7 Apr 2026 10:21:22 -0400 Subject: [PATCH 1/2] Work around Safari bug with negative margins used in bussproofs. (mathjax/MathJax#3547) --- .../tex/__snapshots__/Bussproofs.test.ts.snap | 181 ++++++------------ ts/input/tex/bussproofs/BussproofsUtil.ts | 37 ++-- 2 files changed, 73 insertions(+), 145 deletions(-) diff --git a/testsuite/tests/input/tex/__snapshots__/Bussproofs.test.ts.snap b/testsuite/tests/input/tex/__snapshots__/Bussproofs.test.ts.snap index f30adfc1e..78e77a56a 100644 --- a/testsuite/tests/input/tex/__snapshots__/Bussproofs.test.ts.snap +++ b/testsuite/tests/input/tex/__snapshots__/Bussproofs.test.ts.snap @@ -616,8 +616,7 @@ exports[`BussproofsRegInf Unary Inference Abbr 1`] = ` exports[`BussproofsRegProofs Extreme 1`] = ` " - - + @@ -630,10 +629,8 @@ exports[`BussproofsRegProofs Extreme 1`] = ` - - - - + + WWW @@ -644,8 +641,7 @@ exports[`BussproofsRegProofs Extreme 1`] = ` - - + HHHHH @@ -700,7 +696,7 @@ exports[`BussproofsRegProofs Extreme 1`] = ` - + BBBB @@ -719,7 +715,7 @@ exports[`BussproofsRegProofs Extreme 1`] = ` - + qqqq @@ -768,7 +764,6 @@ exports[`BussproofsRegProofs Extreme 1`] = ` AAAA - @@ -789,7 +784,6 @@ exports[`BussproofsRegProofs Extreme 1`] = ` MMM - @@ -853,22 +847,18 @@ exports[`BussproofsRegProofs Extreme 1`] = ` exports[`BussproofsRegProofs Proof Complex 1`] = ` " - - - - - + + + - - - - - + + + @@ -876,10 +866,8 @@ exports[`BussproofsRegProofs Proof Complex 1`] = ` - - - - + + @@ -887,8 +875,7 @@ exports[`BussproofsRegProofs Proof Complex 1`] = ` - - + @@ -1019,7 +1006,7 @@ exports[`BussproofsRegProofs Proof Complex 1`] = ` - + @@ -1063,7 +1050,6 @@ exports[`BussproofsRegProofs Proof Complex 1`] = ` - @@ -1095,7 +1081,6 @@ exports[`BussproofsRegProofs Proof Complex 1`] = ` - @@ -1135,29 +1120,24 @@ exports[`BussproofsRegProofs Proof Complex 1`] = ` - " `; exports[`BussproofsRegProofs Proof Mixing Order 1`] = ` " - - - - - + + + - - - - - + + + @@ -1165,10 +1145,8 @@ exports[`BussproofsRegProofs Proof Mixing Order 1`] = ` - - - - + + @@ -1176,8 +1154,7 @@ exports[`BussproofsRegProofs Proof Mixing Order 1`] = ` - - + @@ -1308,7 +1285,7 @@ exports[`BussproofsRegProofs Proof Mixing Order 1`] = ` - + @@ -1352,7 +1329,6 @@ exports[`BussproofsRegProofs Proof Mixing Order 1`] = ` - @@ -1384,7 +1360,6 @@ exports[`BussproofsRegProofs Proof Mixing Order 1`] = ` - @@ -1424,25 +1399,21 @@ exports[`BussproofsRegProofs Proof Mixing Order 1`] = ` - " `; exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` " - - + - - - - + + @@ -1450,8 +1421,7 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` - - + @@ -1503,7 +1473,7 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` - + @@ -1519,7 +1489,7 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` - + @@ -1565,7 +1535,6 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` Nowhere - @@ -1586,7 +1555,6 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` BBB - @@ -1626,7 +1594,7 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` - + @@ -1658,7 +1626,6 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` QERE - @@ -1709,14 +1676,13 @@ exports[`BussproofsRegProofs Proof Very Right Label 1`] = ` - " `; exports[`BussproofsRegProofs Simple Proof 1`] = ` " - + @@ -1731,7 +1697,7 @@ exports[`BussproofsRegProofs Simple Proof 1`] = ` - + @@ -1801,7 +1767,6 @@ exports[`BussproofsRegProofs Simple Proof 1`] = ` - @@ -1818,31 +1783,27 @@ exports[`BussproofsRegProofs Simple Proof 1`] = ` - " `; exports[`BussproofsRegProofs Simple Proof Large 1`] = ` " - - + - - + - - + @@ -1889,7 +1850,7 @@ exports[`BussproofsRegProofs Simple Proof Large 1`] = ` - + @@ -1959,7 +1920,6 @@ exports[`BussproofsRegProofs Simple Proof Large 1`] = ` - @@ -2012,7 +1972,7 @@ exports[`BussproofsRegProofs Simple Proof Large 1`] = ` exports[`BussproofsRegProofs Simple Proof Noise 1`] = ` " - + $ α $ @@ -2030,7 +1990,7 @@ exports[`BussproofsRegProofs Simple Proof Noise 1`] = ` - + @@ -2100,7 +2060,6 @@ exports[`BussproofsRegProofs Simple Proof Noise 1`] = ` - @@ -2117,15 +2076,13 @@ exports[`BussproofsRegProofs Simple Proof Noise 1`] = ` - " `; exports[`BussproofsRegProofs Simple Proofs Left Labels 1`] = ` " - - + @@ -2138,12 +2095,9 @@ exports[`BussproofsRegProofs Simple Proofs Left Labels 1`] = ` - - - - - - + + + CCCCC @@ -2153,8 +2107,7 @@ exports[`BussproofsRegProofs Simple Proofs Left Labels 1`] = ` - - + @@ -2201,7 +2154,7 @@ exports[`BussproofsRegProofs Simple Proofs Left Labels 1`] = ` - + BBB @@ -2281,7 +2234,6 @@ exports[`BussproofsRegProofs Simple Proofs Left Labels 1`] = ` - @@ -2337,8 +2289,7 @@ exports[`BussproofsRegProofs Simple Proofs Left Labels 1`] = ` exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` " - - + @@ -2351,12 +2302,9 @@ exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` - - - - - - + + + CCCCC @@ -2366,8 +2314,7 @@ exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` - - + @@ -2414,7 +2361,7 @@ exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` - + BBB @@ -2433,7 +2380,7 @@ exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` - + @@ -2479,7 +2426,6 @@ exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` AAAA - @@ -2497,7 +2443,6 @@ exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` - @@ -2558,8 +2503,7 @@ exports[`BussproofsRegProofs Simple Proofs Mixed Labels 1`] = ` exports[`BussproofsRegProofs Simple Proofs Right Labels 1`] = ` " - - + @@ -2567,10 +2511,8 @@ exports[`BussproofsRegProofs Simple Proofs Right Labels 1`] = ` - - - - + + @@ -2578,8 +2520,7 @@ exports[`BussproofsRegProofs Simple Proofs Right Labels 1`] = ` - - + @@ -2626,7 +2567,7 @@ exports[`BussproofsRegProofs Simple Proofs Right Labels 1`] = ` - + @@ -2642,7 +2583,7 @@ exports[`BussproofsRegProofs Simple Proofs Right Labels 1`] = ` - + @@ -2688,7 +2629,6 @@ exports[`BussproofsRegProofs Simple Proofs Right Labels 1`] = ` AAAA - @@ -2709,7 +2649,6 @@ exports[`BussproofsRegProofs Simple Proofs Right Labels 1`] = ` BBB - diff --git a/ts/input/tex/bussproofs/BussproofsUtil.ts b/ts/input/tex/bussproofs/BussproofsUtil.ts index 3e1caccc6..514200d87 100644 --- a/ts/input/tex/bussproofs/BussproofsUtil.ts +++ b/ts/input/tex/bussproofs/BussproofsUtil.ts @@ -52,7 +52,7 @@ let item: MATHITEM = null; * @param {MmlNode} node The target node. * @returns {number} Width of the proof node. */ -const getBBox = function (node: MmlNode) { +const getBBox = function (node: MmlNode): number { item.root = node; const { w: width } = (doc.outputJax as any).getBBox(item, doc); return width; @@ -190,8 +190,8 @@ const getParentInf = function (inf: MmlNode): MmlNode { return inf; }; -// Computes bbox spaces // +// Computes bbox spaces // /** @@ -214,6 +214,8 @@ const getSpaces = function ( return result; } if (inf !== rule.parent) { + result += + (inf.getProperty(right ? 'proof-right' : 'proof-left') as number) || 0; const children = inf.childNodes; const index = right ? children.length - 1 : 0; if (NodeUtil.isType(children[index], 'mspace')) { @@ -278,29 +280,16 @@ const addSpace = function ( moveProperties(inf, mrow); inf = mrow; } - // TODO: Simplify below as we now have a definite mrow. - const index = right ? inf.childNodes.length - 1 : 0; - let mspace = inf.childNodes[index]; - if (NodeUtil.isType(mspace, 'mspace')) { - NodeUtil.setAttribute( - mspace, - 'width', - UnitUtil.em( - UnitUtil.dimen2em(NodeUtil.getAttribute(mspace, 'width') as string) + - space - ) - ); - return; - } - mspace = config.nodeFactory.create('node', 'mspace', [], { - width: UnitUtil.em(space), - }); - if (right) { - inf.appendChild(mspace); - return; + const prop = right ? 'proof-right' : 'proof-left'; + inf.setProperty(prop, ((inf.getProperty(prop) as number) || 0) + space); + const styles = []; + for (const side of ['left', 'right']) { + const margin = inf.getProperty(`proof-${side}`) as number; + if (margin) { + styles.push(`margin-${side}: ${UnitUtil.em(margin)}`); + } } - mspace.parent = inf; - inf.childNodes.unshift(mspace); + inf.attributes.set('style', styles.join('; ')); }; /** From ab4dbad4821cfe1b261121559c3f1e1b2f7eabd5 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 9 Apr 2026 08:13:02 -0400 Subject: [PATCH 2/2] Remove unneeded check for mspace since they are no longer used --- ts/input/tex/bussproofs/BussproofsUtil.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ts/input/tex/bussproofs/BussproofsUtil.ts b/ts/input/tex/bussproofs/BussproofsUtil.ts index 514200d87..a69d5f0c6 100644 --- a/ts/input/tex/bussproofs/BussproofsUtil.ts +++ b/ts/input/tex/bussproofs/BussproofsUtil.ts @@ -216,11 +216,6 @@ const getSpaces = function ( if (inf !== rule.parent) { result += (inf.getProperty(right ? 'proof-right' : 'proof-left') as number) || 0; - const children = inf.childNodes; - const index = right ? children.length - 1 : 0; - if (NodeUtil.isType(children[index], 'mspace')) { - result += getBBox(children[index]); - } inf = rule.parent; } if (inf === rule) {