Skip to content

Commit 3d2a44c

Browse files
authored
Merge pull request #697 from mathjax/mathtools-update
Mathtools update
2 parents 3e2c672 + ced45f9 commit 3d2a44c

26 files changed

Lines changed: 1715 additions & 178 deletions

components/src/dependencies.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const dependencies = {
2121
'[tex]/enclose': ['input/tex-base'],
2222
'[tex]/extpfeil': ['input/tex-base', '[tex]/newcommand', '[tex]/ams'],
2323
'[tex]/html': ['input/tex-base'],
24+
'[tex]/mathtools': ['input/tex-base', '[tex]/newcommand', '[tex]/ams'],
2425
'[tex]/mhchem': ['input/tex-base', '[tex]/ams'],
2526
'[tex]/newcommand': ['input/tex-base'],
2627
'[tex]/noerrors': ['input/tex-base'],
@@ -56,6 +57,7 @@ const allPackages = [
5657
'[tex]/enclose',
5758
'[tex]/extpfeil',
5859
'[tex]/html',
60+
'[tex]/mathtools',
5961
'[tex]/mhchem',
6062
'[tex]/newcommand',
6163
'[tex]/noerrors',
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": "input/tex/extensions/mathtools",
3+
"targets": ["input/tex/mathtools"]
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './lib/mathtools.js';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const PACKAGE = require('../../../../../webpack.common.js');
2+
3+
module.exports = PACKAGE(
4+
'input/tex/extensions/mathtools', // the package to build
5+
'../../../../../../js', // location of the MathJax js library
6+
[ // packages to link to
7+
'components/src/input/tex/extensions/ams/lib',
8+
'components/src/input/tex/extensions/newcommand/lib',
9+
'components/src/input/tex-base/lib',
10+
'components/src/core/lib'
11+
],
12+
__dirname // our directory
13+
);

components/src/source.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const source = {
2323
'[tex]/enclose': `${src}/input/tex/extensions/enclose/enclose.js`,
2424
'[tex]/extpfeil': `${src}/input/tex/extensions/extpfeil/extpfeil.js`,
2525
'[tex]/html': `${src}/input/tex/extensions/html/html.js`,
26+
'[tex]/mathtools': `${src}/input/tex/extensions/mathtools/mathtools.js`,
2627
'[tex]/mhchem': `${src}/input/tex/extensions/mhchem/mhchem.js`,
2728
'[tex]/newcommand': `${src}/input/tex/extensions/newcommand/newcommand.js`,
2829
'[tex]/noerrors': `${src}/input/tex/extensions/noerrors/noerrors.js`,

ts/core/MmlTree/MmlNodes/mstyle.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ export class MmlMstyle extends AbstractMmlLayoutNode {
7575
} else {
7676
level = parseInt(scriptlevel);
7777
}
78+
prime = false; // style change resets tex prime style
7879
}
7980
let displaystyle = this.attributes.getExplicit('displaystyle') as boolean;
8081
if (displaystyle != null) {
8182
display = (displaystyle === true);
83+
prime = false; // style change resets tex prime style
84+
}
85+
const cramped = this.attributes.getExplicit('data-cramped') as boolean; // manual control of tex prime style
86+
if (cramped != null) {
87+
prime = cramped;
8288
}
8389
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
8490
this.childNodes[0].setInheritedAttributes(attributes, display, level, prime);

ts/core/MmlTree/MmlNodes/mtable.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ export class MmlMtable extends AbstractMmlNode {
106106
/**
107107
* Make sure all children are mtr or mlabeledtr nodes
108108
* Inherit the table attributes, and set the display attribute based on the table's displaystyle attribute
109+
* Reset the prime value to false
109110
*
110111
* @override
111112
*/
112-
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
113+
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, _prime: boolean) {
113114
for (const child of this.childNodes) {
114115
if (!child.isKind('mtr')) {
115116
this.replaceChild(this.factory.create('mtr'), child)
@@ -122,10 +123,11 @@ export class MmlMtable extends AbstractMmlNode {
122123
columnalign: this.attributes.get('columnalign'),
123124
rowalign: 'center'
124125
});
126+
const cramped = this.attributes.getExplicit('data-cramped') as boolean;
125127
const ralign = split(this.attributes.get('rowalign') as string);
126128
for (const child of this.childNodes) {
127129
attributes.rowalign[1] = ralign.shift() || attributes.rowalign[1];
128-
child.setInheritedAttributes(attributes, display, level, prime);
130+
child.setInheritedAttributes(attributes, display, level, !!cramped);
129131
}
130132
}
131133

ts/input/tex/AllPackages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import './enclose/EncloseConfiguration.js';
3939
import './extpfeil/ExtpfeilConfiguration.js';
4040
import './gensymb/GensymbConfiguration.js';
4141
import './html/HtmlConfiguration.js';
42+
import './mathtools/MathtoolsConfiguration.js';
4243
import './mhchem/MhchemConfiguration.js';
4344
import './newcommand/NewcommandConfiguration.js';
4445
import './noerrors/NoErrorsConfiguration.js';
@@ -70,6 +71,7 @@ if (typeof MathJax !== 'undefined' && MathJax.loader) {
7071
'[tex]/extpfeil',
7172
'[tex]/gensymb',
7273
'[tex]/html',
74+
'[tex]/mathtools',
7375
'[tex]/mhchem',
7476
'[tex]/newcommand',
7577
'[tex]/noerrors',
@@ -102,6 +104,7 @@ export const AllPackages: string[] = [
102104
'extpfeil',
103105
'gensymb',
104106
'html',
107+
'mathtools',
105108
'mhchem',
106109
'newcommand',
107110
'noerrors',

ts/input/tex/ParseUtil.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import NodeUtil from './NodeUtil.js';
3030
import TexParser from './TexParser.js';
3131
import TexError from './TexError.js';
3232
import {entities} from '../../util/Entities.js';
33+
import {MmlMunderover} from '../../core/MmlTree/MmlNodes/munderover.js';
3334
import {em} from '../../util/lengths.js';
3435

3536

@@ -360,6 +361,40 @@ namespace ParseUtil {
360361
return parser.create('node', 'mtext', [], def, textNode);
361362
}
362363

364+
/**
365+
* Create an munderover node with the given script position.
366+
* @param {TexParser} parser The current TeX parser.
367+
* @param {MmlNode} base The base node.
368+
* @param {MmlNode} script The under- or over-script.
369+
* @param {string} pos Either 'over' or 'under'.
370+
* @param {boolean} stack True if super- or sub-scripts should stack.
371+
* @return {MmlNode} The generated node (MmlMunderover or TeXAtom)
372+
*/
373+
export function underOver(parser: TexParser, base: MmlNode, script: MmlNode, pos: string, stack: boolean): MmlNode {
374+
// @test Overline
375+
const symbol = NodeUtil.getForm(base);
376+
if ((symbol && symbol[3] && symbol[3]['movablelimits']) || NodeUtil.getProperty(base, 'movablelimits')) {
377+
// @test Overline Sum
378+
NodeUtil.setProperties(base, {'movablelimits': false});
379+
}
380+
if (NodeUtil.isType(base, 'munderover') && NodeUtil.isEmbellished(base)) {
381+
// @test Overline Limits
382+
NodeUtil.setProperties(NodeUtil.getCoreMO(base), {lspace: 0, rspace: 0});
383+
const mo = parser.create('node', 'mo', [], {rspace: 0});
384+
base = parser.create('node', 'mrow', [mo, base]);
385+
// TODO? add an empty <mi> so it's not embellished any more
386+
}
387+
const mml = parser.create('node', 'munderover', [base]) as MmlMunderover;
388+
NodeUtil.setChild(mml, pos === 'over' ? mml.over : mml.under, script);
389+
let node: MmlNode = mml;
390+
if (stack) {
391+
// @test Overbrace 1 2 3, Underbrace, Overbrace Op 1 2
392+
node = parser.create('node', 'TeXAtom', [mml], {texClass: TEXCLASS.OP, movesupsub: true});
393+
}
394+
NodeUtil.setProperty(node, 'subsupOK', true);
395+
return node;
396+
}
397+
363398
/**
364399
* Trim spaces from a string.
365400
* @param {string} text The string to clean.
@@ -391,7 +426,7 @@ namespace ParseUtil {
391426
} else if (align === 'b') {
392427
array.arraydef.align = 'baseline -1';
393428
} else if (align === 'c') {
394-
array.arraydef.align = 'center';
429+
array.arraydef.align = 'axis';
395430
} else if (align) {
396431
array.arraydef.align = align;
397432
} // FIXME: should be an error?
@@ -458,6 +493,26 @@ namespace ParseUtil {
458493
return s1 + s2;
459494
}
460495

496+
/**
497+
* Report an error if there are too many macro substitutions.
498+
* @param {TexParser} parser The current TeX parser.
499+
* @param {boolean} isMacro True if we are substituting a macro, false for environment.
500+
*/
501+
export function checkMaxMacros(parser: TexParser, isMacro: boolean = true) {
502+
if (++parser.macroCount <= parser.configuration.options['maxMacros']) {
503+
return;
504+
}
505+
if (isMacro) {
506+
throw new TexError('MaxMacroSub1',
507+
'MathJax maximum macro substitution count exceeded; ' +
508+
'is here a recursive macro call?');
509+
} else {
510+
throw new TexError('MaxMacroSub2',
511+
'MathJax maximum substitution count exceeded; ' +
512+
'is there a recursive latex environment?');
513+
}
514+
}
515+
461516

462517
/**
463518
* Check for bad nesting of equation environments
@@ -513,8 +568,7 @@ namespace ParseUtil {
513568
for (let key of Object.keys(def)) {
514569
if (!allowed.hasOwnProperty(key)) {
515570
if (error) {
516-
throw new TexError('InvalidOption',
517-
'Invalid optional argument: %1', key);
571+
throw new TexError('InvalidOption', 'Invalid option: %1', key);
518572
}
519573
delete def[key];
520574
}

ts/input/tex/ams/AmsMappings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ new sm.CommandMap('AMSmath-macros', {
8989
shoveleft: ['HandleShove', TexConstant.Align.LEFT],
9090
shoveright: ['HandleShove', TexConstant.Align.RIGHT],
9191

92-
xrightarrow: ['xArrow', 0x2192, 7, 12],
92+
xrightarrow: ['xArrow', 0x2192, 5, 10],
9393
xleftarrow: ['xArrow', 0x2190, 10, 5]
9494
}, AmsMethods);
9595

0 commit comments

Comments
 (0)