Skip to content

Commit 7fd8e44

Browse files
committed
Make over/under braces and matrices be full size, as in actual TeX (mathjax/MathJax#3300)
1 parent 9b6e85a commit 7fd8e44

File tree

10 files changed

+46
-18
lines changed

10 files changed

+46
-18
lines changed

Diff for: ts/core/MmlTree/MmlNode.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -771,14 +771,8 @@ export abstract class AbstractMmlNode
771771
delete attributes[key];
772772
}
773773
}
774-
const displaystyle = this.attributes.getExplicit('displaystyle');
775-
if (displaystyle === undefined) {
776-
this.attributes.setInherited('displaystyle', display);
777-
}
778-
const scriptlevel = this.attributes.getExplicit('scriptlevel');
779-
if (scriptlevel === undefined) {
780-
this.attributes.setInherited('scriptlevel', level);
781-
}
774+
this.attributes.setInherited('displaystyle', display);
775+
this.attributes.setInherited('scriptlevel', level);
782776
if (prime) {
783777
this.setProperty('texprimestyle', prime);
784778
}

Diff for: ts/core/MmlTree/MmlNodes/mtable.ts

-1
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')

Diff for: ts/core/MmlTree/MmlVisitor.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ export class MmlVisitor extends AbstractVisitor<MmlNode> {
201201
texclass < 0 ? 'NONE' : TEXCLASSNAMES[texclass]
202202
);
203203
}
204-
node.getProperty('scriptlevel') &&
205-
node.getProperty('useHeight') === false &&
204+
node.getProperty('smallmatrix') &&
206205
this.setDataAttribute(data, 'smallmatrix', 'true');
207206
return data;
208207
}

Diff for: ts/input/mathml/MathMLCompile.ts

+1-1
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':

Diff for: ts/input/tex.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ export class TeX<N, T, D> extends AbstractInputJax<N, T, D> {
157157
userOptions(parseOptions.options, rest);
158158
configuration.config(this);
159159
TeX.tags(parseOptions, configuration);
160-
this.postFilters.add(FilterUtil.cleanSubSup, -6);
161-
this.postFilters.add(FilterUtil.setInherited, -5);
160+
this.postFilters.add(FilterUtil.cleanSubSup, -7);
161+
this.postFilters.add(FilterUtil.setInherited, -6);
162+
this.postFilters.add(FilterUtil.checkScriptlevel, -5);
162163
this.postFilters.add(FilterUtil.moveLimits, -4);
163164
this.postFilters.add(FilterUtil.cleanStretchy, -3);
164165
this.postFilters.add(FilterUtil.cleanAttributes, -2);

Diff for: ts/input/tex/FilterUtil.ts

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

338366
export default FilterUtil;

Diff for: ts/input/tex/ParseUtil.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,9 @@ export const ParseUtil = {
637637
let node: MmlNode = mml;
638638
if (stack) {
639639
// @test Overbrace 1 2 3, Underbrace, Overbrace Op 1 2
640-
node = parser.create('node', 'TeXAtom', [mml], {
640+
node = parser.create('node', 'TeXAtom', [
641+
parser.create('node', 'mstyle', [mml], { displaystyle: true, scriptlevel: 0 })
642+
], {
641643
texClass: TEXCLASS.OP,
642644
movesupsub: true,
643645
});

Diff for: ts/input/tex/ams/AmsMappings.ts

+2-2
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'],

Diff for: ts/input/tex/base/BaseItems.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ export class ArrayItem extends BaseItem {
10921092
delete this.arraydef['scriptlevel'];
10931093
let mml = this.create('node', 'mtable', this.table, this.arraydef);
10941094
if (scriptlevel) {
1095-
mml.setProperty('scriptlevel', scriptlevel);
1095+
mml.setProperty('smallmatrix', true);
10961096
}
10971097
if (this.breakAlign.table) {
10981098
NodeUtil.setAttribute(mml, 'data-break-align', this.breakAlign.table);
@@ -1106,6 +1106,9 @@ export class ArrayItem extends BaseItem {
11061106
);
11071107
}
11081108
mml = this.handleFrame(mml);
1109+
if (scriptlevel !== undefined) {
1110+
mml = this.create('node', 'mstyle', [mml], { scriptlevel });
1111+
}
11091112
if (this.getProperty('open') || this.getProperty('close')) {
11101113
// @test Cross Product Formula
11111114
mml = ParseUtil.fenced(

Diff for: ts/input/tex/base/BaseMethods.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,8 @@ const BaseMethods: { [key: string]: ParseMethod } = {
19611961
if (style === 'S') {
19621962
// @test Subarray, Small Matrix
19631963
array.arraydef['scriptlevel'] = 1;
1964+
} else {
1965+
array.arraydef['scriptlevel'] = 0;
19641966
}
19651967
if (raggedHeight) {
19661968
// @test Subarray, Small Matrix

0 commit comments

Comments
 (0)