Skip to content

Commit

Permalink
Merge pull request #697 from mathjax/mathtools-update
Browse files Browse the repository at this point in the history
Mathtools update
  • Loading branch information
dpvc committed Jun 8, 2021
2 parents 3e2c672 + ced45f9 commit 3d2a44c
Show file tree
Hide file tree
Showing 26 changed files with 1,715 additions and 178 deletions.
2 changes: 2 additions & 0 deletions components/src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const dependencies = {
'[tex]/enclose': ['input/tex-base'],
'[tex]/extpfeil': ['input/tex-base', '[tex]/newcommand', '[tex]/ams'],
'[tex]/html': ['input/tex-base'],
'[tex]/mathtools': ['input/tex-base', '[tex]/newcommand', '[tex]/ams'],
'[tex]/mhchem': ['input/tex-base', '[tex]/ams'],
'[tex]/newcommand': ['input/tex-base'],
'[tex]/noerrors': ['input/tex-base'],
Expand Down Expand Up @@ -56,6 +57,7 @@ const allPackages = [
'[tex]/enclose',
'[tex]/extpfeil',
'[tex]/html',
'[tex]/mathtools',
'[tex]/mhchem',
'[tex]/newcommand',
'[tex]/noerrors',
Expand Down
4 changes: 4 additions & 0 deletions components/src/input/tex/extensions/mathtools/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"component": "input/tex/extensions/mathtools",
"targets": ["input/tex/mathtools"]
}
1 change: 1 addition & 0 deletions components/src/input/tex/extensions/mathtools/mathtools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './lib/mathtools.js';
13 changes: 13 additions & 0 deletions components/src/input/tex/extensions/mathtools/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const PACKAGE = require('../../../../../webpack.common.js');

module.exports = PACKAGE(
'input/tex/extensions/mathtools', // the package to build
'../../../../../../js', // location of the MathJax js library
[ // packages to link to
'components/src/input/tex/extensions/ams/lib',
'components/src/input/tex/extensions/newcommand/lib',
'components/src/input/tex-base/lib',
'components/src/core/lib'
],
__dirname // our directory
);
1 change: 1 addition & 0 deletions components/src/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const source = {
'[tex]/enclose': `${src}/input/tex/extensions/enclose/enclose.js`,
'[tex]/extpfeil': `${src}/input/tex/extensions/extpfeil/extpfeil.js`,
'[tex]/html': `${src}/input/tex/extensions/html/html.js`,
'[tex]/mathtools': `${src}/input/tex/extensions/mathtools/mathtools.js`,
'[tex]/mhchem': `${src}/input/tex/extensions/mhchem/mhchem.js`,
'[tex]/newcommand': `${src}/input/tex/extensions/newcommand/newcommand.js`,
'[tex]/noerrors': `${src}/input/tex/extensions/noerrors/noerrors.js`,
Expand Down
6 changes: 6 additions & 0 deletions ts/core/MmlTree/MmlNodes/mstyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ export class MmlMstyle extends AbstractMmlLayoutNode {
} else {
level = parseInt(scriptlevel);
}
prime = false; // style change resets tex prime style
}
let displaystyle = this.attributes.getExplicit('displaystyle') as boolean;
if (displaystyle != null) {
display = (displaystyle === true);
prime = false; // style change resets tex prime style
}
const cramped = this.attributes.getExplicit('data-cramped') as boolean; // manual control of tex prime style
if (cramped != null) {
prime = cramped;
}
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
this.childNodes[0].setInheritedAttributes(attributes, display, level, prime);
Expand Down
6 changes: 4 additions & 2 deletions ts/core/MmlTree/MmlNodes/mtable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ export class MmlMtable extends AbstractMmlNode {
/**
* Make sure all children are mtr or mlabeledtr nodes
* Inherit the table attributes, and set the display attribute based on the table's displaystyle attribute
* Reset the prime value to false
*
* @override
*/
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, _prime: boolean) {
for (const child of this.childNodes) {
if (!child.isKind('mtr')) {
this.replaceChild(this.factory.create('mtr'), child)
Expand All @@ -122,10 +123,11 @@ export class MmlMtable extends AbstractMmlNode {
columnalign: this.attributes.get('columnalign'),
rowalign: 'center'
});
const cramped = this.attributes.getExplicit('data-cramped') as boolean;
const ralign = split(this.attributes.get('rowalign') as string);
for (const child of this.childNodes) {
attributes.rowalign[1] = ralign.shift() || attributes.rowalign[1];
child.setInheritedAttributes(attributes, display, level, prime);
child.setInheritedAttributes(attributes, display, level, !!cramped);
}
}

Expand Down
3 changes: 3 additions & 0 deletions ts/input/tex/AllPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import './enclose/EncloseConfiguration.js';
import './extpfeil/ExtpfeilConfiguration.js';
import './gensymb/GensymbConfiguration.js';
import './html/HtmlConfiguration.js';
import './mathtools/MathtoolsConfiguration.js';
import './mhchem/MhchemConfiguration.js';
import './newcommand/NewcommandConfiguration.js';
import './noerrors/NoErrorsConfiguration.js';
Expand Down Expand Up @@ -70,6 +71,7 @@ if (typeof MathJax !== 'undefined' && MathJax.loader) {
'[tex]/extpfeil',
'[tex]/gensymb',
'[tex]/html',
'[tex]/mathtools',
'[tex]/mhchem',
'[tex]/newcommand',
'[tex]/noerrors',
Expand Down Expand Up @@ -102,6 +104,7 @@ export const AllPackages: string[] = [
'extpfeil',
'gensymb',
'html',
'mathtools',
'mhchem',
'newcommand',
'noerrors',
Expand Down
60 changes: 57 additions & 3 deletions ts/input/tex/ParseUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import NodeUtil from './NodeUtil.js';
import TexParser from './TexParser.js';
import TexError from './TexError.js';
import {entities} from '../../util/Entities.js';
import {MmlMunderover} from '../../core/MmlTree/MmlNodes/munderover.js';
import {em} from '../../util/lengths.js';


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

/**
* Create an munderover node with the given script position.
* @param {TexParser} parser The current TeX parser.
* @param {MmlNode} base The base node.
* @param {MmlNode} script The under- or over-script.
* @param {string} pos Either 'over' or 'under'.
* @param {boolean} stack True if super- or sub-scripts should stack.
* @return {MmlNode} The generated node (MmlMunderover or TeXAtom)
*/
export function underOver(parser: TexParser, base: MmlNode, script: MmlNode, pos: string, stack: boolean): MmlNode {
// @test Overline
const symbol = NodeUtil.getForm(base);
if ((symbol && symbol[3] && symbol[3]['movablelimits']) || NodeUtil.getProperty(base, 'movablelimits')) {
// @test Overline Sum
NodeUtil.setProperties(base, {'movablelimits': false});
}
if (NodeUtil.isType(base, 'munderover') && NodeUtil.isEmbellished(base)) {
// @test Overline Limits
NodeUtil.setProperties(NodeUtil.getCoreMO(base), {lspace: 0, rspace: 0});
const mo = parser.create('node', 'mo', [], {rspace: 0});
base = parser.create('node', 'mrow', [mo, base]);
// TODO? add an empty <mi> so it's not embellished any more
}
const mml = parser.create('node', 'munderover', [base]) as MmlMunderover;
NodeUtil.setChild(mml, pos === 'over' ? mml.over : mml.under, script);
let node: MmlNode = mml;
if (stack) {
// @test Overbrace 1 2 3, Underbrace, Overbrace Op 1 2
node = parser.create('node', 'TeXAtom', [mml], {texClass: TEXCLASS.OP, movesupsub: true});
}
NodeUtil.setProperty(node, 'subsupOK', true);
return node;
}

/**
* Trim spaces from a string.
* @param {string} text The string to clean.
Expand Down Expand Up @@ -391,7 +426,7 @@ namespace ParseUtil {
} else if (align === 'b') {
array.arraydef.align = 'baseline -1';
} else if (align === 'c') {
array.arraydef.align = 'center';
array.arraydef.align = 'axis';
} else if (align) {
array.arraydef.align = align;
} // FIXME: should be an error?
Expand Down Expand Up @@ -458,6 +493,26 @@ namespace ParseUtil {
return s1 + s2;
}

/**
* Report an error if there are too many macro substitutions.
* @param {TexParser} parser The current TeX parser.
* @param {boolean} isMacro True if we are substituting a macro, false for environment.
*/
export function checkMaxMacros(parser: TexParser, isMacro: boolean = true) {
if (++parser.macroCount <= parser.configuration.options['maxMacros']) {
return;
}
if (isMacro) {
throw new TexError('MaxMacroSub1',
'MathJax maximum macro substitution count exceeded; ' +
'is here a recursive macro call?');
} else {
throw new TexError('MaxMacroSub2',
'MathJax maximum substitution count exceeded; ' +
'is there a recursive latex environment?');
}
}


/**
* Check for bad nesting of equation environments
Expand Down Expand Up @@ -513,8 +568,7 @@ namespace ParseUtil {
for (let key of Object.keys(def)) {
if (!allowed.hasOwnProperty(key)) {
if (error) {
throw new TexError('InvalidOption',
'Invalid optional argument: %1', key);
throw new TexError('InvalidOption', 'Invalid option: %1', key);
}
delete def[key];
}
Expand Down
2 changes: 1 addition & 1 deletion ts/input/tex/ams/AmsMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ new sm.CommandMap('AMSmath-macros', {
shoveleft: ['HandleShove', TexConstant.Align.LEFT],
shoveright: ['HandleShove', TexConstant.Align.RIGHT],

xrightarrow: ['xArrow', 0x2192, 7, 12],
xrightarrow: ['xArrow', 0x2192, 5, 10],
xleftarrow: ['xArrow', 0x2190, 10, 5]
}, AmsMethods);

Expand Down
23 changes: 23 additions & 0 deletions ts/input/tex/base/BaseItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,29 @@ export class ArrayItem extends BaseItem {
}
}

/**
* Adds a row-spacing to the current row (padding out the rowspacing if needed to get there).
*
* @param {string} spacing The rowspacing to use for the current row.
*/
public addRowSpacing(spacing: string) {
if (this.arraydef['rowspacing']) {
const rows = (this.arraydef['rowspacing'] as string).split(/ /);
if (!this.getProperty('rowspacing')) {
// @test Array Custom Linebreak
let dimem = ParseUtil.dimen2em(rows[0]);
this.setProperty('rowspacing', dimem);
}
const rowspacing = this.getProperty('rowspacing') as number;
while (rows.length < this.table.length) {
rows.push(ParseUtil.Em(rowspacing));
}
rows[this.table.length - 1] = ParseUtil.Em(
Math.max(0, rowspacing + ParseUtil.dimen2em(spacing)));
this.arraydef['rowspacing'] = rows.join(' ');
}
}

}


Expand Down
2 changes: 2 additions & 0 deletions ts/input/tex/base/BaseMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ new sm.CommandMap('macros', {
text: 'HBox',
mbox: ['HBox', 0],
fbox: 'FBox',
boxed: ['Macro', '\\fbox{$\\displaystyle{#1}$}', 1],
framebox: 'FrameBox',

strut: 'Strut',
mathstrut: ['Macro', '\\vphantom{(}'],
Expand Down
Loading

0 comments on commit 3d2a44c

Please sign in to comment.