Skip to content

Commit 7f08013

Browse files
authored
Merge pull request #1146 from mathjax/issue3300
Make over/under braces and matrices be full size, as in actual TeX (mathjax/MathJax#3300)
2 parents 5625751 + be6f39e commit 7f08013

10 files changed

Lines changed: 59 additions & 23 deletions

File tree

ts/core/MmlTree/MmlNode.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,8 @@ export abstract class AbstractMmlNode
772772
delete attributes[key];
773773
}
774774
}
775-
const displaystyle = this.attributes.getExplicit('displaystyle');
776-
if (displaystyle === undefined) {
777-
this.attributes.setInherited('displaystyle', display);
778-
}
779-
const scriptlevel = this.attributes.getExplicit('scriptlevel');
780-
if (scriptlevel === undefined) {
781-
this.attributes.setInherited('scriptlevel', level);
782-
}
775+
this.attributes.setInherited('displaystyle', display);
776+
this.attributes.setInherited('scriptlevel', level);
783777
if (prime) {
784778
this.setProperty('texprimestyle', prime);
785779
}

ts/core/MmlTree/MmlNodes/mtable.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ export class MmlMtable extends AbstractMmlNode {
142142
this.replaceChild(this.factory.create('mtr'), child).appendChild(child);
143143
}
144144
}
145-
level = (this.getProperty('scriptlevel') as number) || level;
146145
display = !!(
147146
this.attributes.getExplicit('displaystyle') ||
148147
this.attributes.getDefault('displaystyle')

ts/core/MmlTree/MmlVisitor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,7 @@ export class MmlVisitor extends AbstractVisitor<MmlNode> {
211211
);
212212
}
213213
}
214-
if (
215-
node.getProperty('scriptlevel') &&
216-
node.getProperty('useHeight') === false
217-
) {
214+
if (node.getProperty('smallmatrix')) {
218215
this.setDataAttribute(data, 'smallmatrix', 'true');
219216
}
220217
return data;

ts/input/mathml/MathMLCompile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export class MathMLCompile<N, T, D> {
215215
ignoreVariant = true;
216216
break;
217217
case 'smallmatrix':
218-
mml.setProperty('scriptlevel', 1);
218+
mml.setProperty('smallmatrix', true);
219219
mml.setProperty('useHeight', false);
220220
break;
221221
case 'mathaccent':

ts/input/tex.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ export class TeX<N, T, D> extends AbstractInputJax<N, T, D> {
159159
userOptions(parseOptions.options, rest);
160160
configuration.config(this);
161161
TeX.tags(parseOptions, configuration);
162-
this.postFilters.add(FilterUtil.cleanSubSup, -6);
163-
this.postFilters.add(FilterUtil.setInherited, -5);
162+
this.postFilters.add(FilterUtil.cleanSubSup, -7);
163+
this.postFilters.add(FilterUtil.setInherited, -6);
164+
this.postFilters.add(FilterUtil.checkScriptlevel, -5);
164165
this.postFilters.add(FilterUtil.moveLimits, -4);
165166
this.postFilters.add(FilterUtil.cleanStretchy, -3);
166167
this.postFilters.add(FilterUtil.cleanAttributes, -2);

ts/input/tex/FilterUtil.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,36 @@ namespace FilterUtil {
333333
}) {
334334
arg.data.root.setInheritedAttributes({}, arg.math['display'], 0, false);
335335
};
336+
337+
/**
338+
* Removes unneeded mstyle elements that just set the scriptlevel
339+
*/
340+
export const checkScriptlevel = function (arg: { data: ParseOptions }) {
341+
const options = arg.data;
342+
const remove: MmlNode[] = [];
343+
for (const mml of options.getList('mstyle')) {
344+
if (mml.childNodes?.[0]?.childNodes?.length !== 1) {
345+
continue;
346+
}
347+
const attributes = mml.attributes;
348+
for (const key of ['displaystyle', 'scriptlevel']) {
349+
if (attributes.getExplicit(key) === attributes.getInherited(key)) {
350+
attributes.unset(key);
351+
}
352+
}
353+
const names = attributes.getExplicitNames();
354+
if (
355+
names.filter((key) => key.substring(0, 10) !== 'data-latex').length ===
356+
0
357+
) {
358+
const child = mml.childNodes[0].childNodes[0];
359+
names.forEach((key) => child.attributes.set(key, attributes.get(key)));
360+
mml.parent.replaceChild(child, mml);
361+
remove.push(mml);
362+
}
363+
}
364+
options.removeFromList('mstyle', remove);
365+
};
336366
}
337367

338368
export default FilterUtil;

ts/input/tex/ParseUtil.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,20 @@ export const ParseUtil = {
639639
let node: MmlNode = mml;
640640
if (stack) {
641641
// @test Overbrace 1 2 3, Underbrace, Overbrace Op 1 2
642-
node = parser.create('node', 'TeXAtom', [mml], {
643-
texClass: TEXCLASS.OP,
644-
movesupsub: true,
645-
});
642+
node = parser.create(
643+
'node',
644+
'TeXAtom',
645+
[
646+
parser.create('node', 'mstyle', [mml], {
647+
displaystyle: true,
648+
scriptlevel: 0,
649+
}),
650+
],
651+
{
652+
texClass: TEXCLASS.OP,
653+
movesupsub: true,
654+
}
655+
);
646656
}
647657
NodeUtil.setProperty(node, 'subsupOK', true);
648658
return node;

ts/input/tex/ams/AmsMappings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ new sm.EnvironmentMap('AMSmath-environment', ParseMethods.environment, {
205205
ParseUtil.cols(0),
206206
'0.1em',
207207
'S',
208-
1,
208+
true,
209209
],
210210
smallmatrix: [
211211
AmsMethods.Array,
@@ -216,7 +216,7 @@ new sm.EnvironmentMap('AMSmath-environment', ParseMethods.environment, {
216216
ParseUtil.cols(1 / 3),
217217
'.2em',
218218
'S',
219-
1,
219+
true,
220220
],
221221
matrix: [AmsMethods.Array, null, null, null, 'c'],
222222
pmatrix: [AmsMethods.Array, null, '(', ')', 'c'],

ts/input/tex/base/BaseItems.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ export class ArrayItem extends BaseItem {
11011101
delete this.arraydef['scriptlevel'];
11021102
let mml = this.create('node', 'mtable', this.table, this.arraydef);
11031103
if (scriptlevel) {
1104-
mml.setProperty('scriptlevel', scriptlevel);
1104+
mml.setProperty('smallmatrix', true);
11051105
}
11061106
if (this.breakAlign.table) {
11071107
NodeUtil.setAttribute(mml, 'data-break-align', this.breakAlign.table);
@@ -1115,6 +1115,9 @@ export class ArrayItem extends BaseItem {
11151115
);
11161116
}
11171117
mml = this.handleFrame(mml);
1118+
if (scriptlevel !== undefined) {
1119+
mml = this.create('node', 'mstyle', [mml], { scriptlevel });
1120+
}
11181121
if (this.getProperty('open') || this.getProperty('close')) {
11191122
// @test Cross Product Formula
11201123
mml = ParseUtil.fenced(

ts/input/tex/base/BaseMethods.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,8 @@ const BaseMethods: { [key: string]: ParseMethod } = {
19681968
if (style === 'S') {
19691969
// @test Subarray, Small Matrix
19701970
array.arraydef['scriptlevel'] = 1;
1971+
} else {
1972+
array.arraydef['scriptlevel'] = 0;
19711973
}
19721974
if (raggedHeight) {
19731975
// @test Subarray, Small Matrix

0 commit comments

Comments
 (0)