Skip to content

Commit

Permalink
Make over/under braces and matrices be full size, as in actual TeX (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Oct 24, 2024
1 parent 9b6e85a commit 7fd8e44
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
10 changes: 2 additions & 8 deletions ts/core/MmlTree/MmlNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,14 +771,8 @@ export abstract class AbstractMmlNode
delete attributes[key];
}
}
const displaystyle = this.attributes.getExplicit('displaystyle');
if (displaystyle === undefined) {
this.attributes.setInherited('displaystyle', display);
}
const scriptlevel = this.attributes.getExplicit('scriptlevel');
if (scriptlevel === undefined) {
this.attributes.setInherited('scriptlevel', level);
}
this.attributes.setInherited('displaystyle', display);
this.attributes.setInherited('scriptlevel', level);
if (prime) {
this.setProperty('texprimestyle', prime);
}
Expand Down
1 change: 0 additions & 1 deletion ts/core/MmlTree/MmlNodes/mtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export class MmlMtable extends AbstractMmlNode {
this.replaceChild(this.factory.create('mtr'), child).appendChild(child);
}
}
level = (this.getProperty('scriptlevel') as number) || level;
display = !!(
this.attributes.getExplicit('displaystyle') ||
this.attributes.getDefault('displaystyle')
Expand Down
3 changes: 1 addition & 2 deletions ts/core/MmlTree/MmlVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ export class MmlVisitor extends AbstractVisitor<MmlNode> {
texclass < 0 ? 'NONE' : TEXCLASSNAMES[texclass]
);
}
node.getProperty('scriptlevel') &&
node.getProperty('useHeight') === false &&
node.getProperty('smallmatrix') &&
this.setDataAttribute(data, 'smallmatrix', 'true');
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion ts/input/mathml/MathMLCompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class MathMLCompile<N, T, D> {
ignoreVariant = true;
break;
case 'smallmatrix':
mml.setProperty('scriptlevel', 1);
mml.setProperty('smallmatrix', true);
mml.setProperty('useHeight', false);
break;
case 'mathaccent':
Expand Down
5 changes: 3 additions & 2 deletions ts/input/tex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ export class TeX<N, T, D> extends AbstractInputJax<N, T, D> {
userOptions(parseOptions.options, rest);
configuration.config(this);
TeX.tags(parseOptions, configuration);
this.postFilters.add(FilterUtil.cleanSubSup, -6);
this.postFilters.add(FilterUtil.setInherited, -5);
this.postFilters.add(FilterUtil.cleanSubSup, -7);
this.postFilters.add(FilterUtil.setInherited, -6);
this.postFilters.add(FilterUtil.checkScriptlevel, -5);
this.postFilters.add(FilterUtil.moveLimits, -4);
this.postFilters.add(FilterUtil.cleanStretchy, -3);
this.postFilters.add(FilterUtil.cleanAttributes, -2);
Expand Down
28 changes: 28 additions & 0 deletions ts/input/tex/FilterUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,34 @@ namespace FilterUtil {
}) {
arg.data.root.setInheritedAttributes({}, arg.math['display'], 0, false);
};


/**
* Removes unneeded mstyle elements that just set the scriptlevel
*/
export const checkScriptlevel = function (arg: { data: ParseOptions }) {
const options = arg.data;
const remove: MmlNode[] = [];
for (const mml of options.getList('mstyle')) {
if (mml.childNodes?.[0]?.childNodes?.length !== 1) {
continue;
}
const attributes = mml.attributes;
for (const key of ['displaystyle', 'scriptlevel']) {
if (attributes.getExplicit(key) === attributes.getInherited(key)) {
attributes.unset(key);
}
}
const names = attributes.getExplicitNames();
if (names.filter(key => key.substring(0, 10) !== 'data-latex').length === 0) {
const child = mml.childNodes[0].childNodes[0];
names.forEach(key => child.attributes.set(key, attributes.get(key)));
mml.parent.replaceChild(child, mml);
remove.push(mml);
}
}
options.removeFromList('mstyle', remove);
}
}

export default FilterUtil;
4 changes: 3 additions & 1 deletion ts/input/tex/ParseUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,9 @@ export const ParseUtil = {
let node: MmlNode = mml;
if (stack) {
// @test Overbrace 1 2 3, Underbrace, Overbrace Op 1 2
node = parser.create('node', 'TeXAtom', [mml], {
node = parser.create('node', 'TeXAtom', [
parser.create('node', 'mstyle', [mml], { displaystyle: true, scriptlevel: 0 })
], {
texClass: TEXCLASS.OP,
movesupsub: true,
});
Expand Down
4 changes: 2 additions & 2 deletions ts/input/tex/ams/AmsMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ new sm.EnvironmentMap('AMSmath-environment', ParseMethods.environment, {
ParseUtil.cols(0),
'0.1em',
'S',
1,
true,
],
smallmatrix: [
AmsMethods.Array,
Expand All @@ -216,7 +216,7 @@ new sm.EnvironmentMap('AMSmath-environment', ParseMethods.environment, {
ParseUtil.cols(1 / 3),
'.2em',
'S',
1,
true,
],
matrix: [AmsMethods.Array, null, null, null, 'c'],
pmatrix: [AmsMethods.Array, null, '(', ')', 'c'],
Expand Down
5 changes: 4 additions & 1 deletion ts/input/tex/base/BaseItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ export class ArrayItem extends BaseItem {
delete this.arraydef['scriptlevel'];
let mml = this.create('node', 'mtable', this.table, this.arraydef);
if (scriptlevel) {
mml.setProperty('scriptlevel', scriptlevel);
mml.setProperty('smallmatrix', true);
}
if (this.breakAlign.table) {
NodeUtil.setAttribute(mml, 'data-break-align', this.breakAlign.table);
Expand All @@ -1106,6 +1106,9 @@ export class ArrayItem extends BaseItem {
);
}
mml = this.handleFrame(mml);
if (scriptlevel !== undefined) {
mml = this.create('node', 'mstyle', [mml], { scriptlevel });
}
if (this.getProperty('open') || this.getProperty('close')) {
// @test Cross Product Formula
mml = ParseUtil.fenced(
Expand Down
2 changes: 2 additions & 0 deletions ts/input/tex/base/BaseMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,8 @@ const BaseMethods: { [key: string]: ParseMethod } = {
if (style === 'S') {
// @test Subarray, Small Matrix
array.arraydef['scriptlevel'] = 1;
} else {
array.arraydef['scriptlevel'] = 0;
}
if (raggedHeight) {
// @test Subarray, Small Matrix
Expand Down

0 comments on commit 7fd8e44

Please sign in to comment.