Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mathtools update #697

Merged
merged 22 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a44ad18
Conversion of mathtools.
zorkow Sep 30, 2020
a2f8364
Correction and cleanup.
zorkow Oct 1, 2020
7c4f3af
Adds two missing case macros.
zorkow Oct 1, 2020
f12b24b
Merge branch 'develop' into mathtools-update
dpvc Apr 28, 2021
d27024f
Make mathtools component and add its source, dependencies, and package
dpvc May 6, 2021
4fe0239
Fix padding used for extra cells added to make all rows the same size…
dpvc May 6, 2021
b1915ea
Make \xrightarrow consistent with \xleftarrow, and don't redefine the…
dpvc May 6, 2021
75e3631
Move UnderOver support to ParseUtil, fix vertical center alignment, a…
dpvc May 6, 2021
dafcfe1
Move checking for max macros into a ParseUtil function, and make a se…
dpvc May 7, 2021
7989667
Make service functions for getting CS name and arg count.
dpvc May 7, 2021
46e88ec
Don't use cramped style for mtables
dpvc May 10, 2021
cdc97af
Add most missing commands and environments
dpvc May 10, 2021
435dad2
Update dependencies
dpvc May 10, 2021
4a6ecbe
Reset tex prime styles for style changes and in tables, and add data-…
dpvc May 11, 2021
350af34
Handle cramped styles better
dpvc May 11, 2021
96bd2cf
Add support for \mathtoolsset
dpvc May 11, 2021
b299037
Add jsdoc comments
dpvc May 11, 2021
3bf820c
Fix typos in comments
dpvc May 11, 2021
34439e7
Fix tsc compile errors
dpvc May 12, 2021
d5ec98e
Make sure style is defined before getting its first character
dpvc May 13, 2021
88fed2f
Make changes requested in review
dpvc Jun 1, 2021
ced45f9
Merge branch 'develop' into mathtools-update
dpvc Jun 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/src/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -49,6 +50,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 @@ -22,6 +22,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;
dpvc marked this conversation as resolved.
Show resolved Hide resolved
}
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 == null ? false : cramped);
dpvc marked this conversation as resolved.
Show resolved Hide resolved
}
}

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 @@ -36,6 +36,7 @@ import './configmacros/ConfigMacrosConfiguration.js';
import './enclose/EncloseConfiguration.js';
import './extpfeil/ExtpfeilConfiguration.js';
import './html/HtmlConfiguration.js';
import './mathtools/MathtoolsConfiguration.js';
import './mhchem/MhchemConfiguration.js';
import './newcommand/NewcommandConfiguration.js';
import './noerrors/NoErrorsConfiguration.js';
Expand All @@ -62,6 +63,7 @@ if (typeof MathJax !== 'undefined' && MathJax.loader) {
'[tex]/enclose',
'[tex]/extpfeil',
'[tex]/html',
'[tex]/mathtools',
'[tex]/mhchem',
'[tex]/newcommand',
'[tex]/noerrors',
Expand Down Expand Up @@ -89,6 +91,7 @@ export const AllPackages: string[] = [
'enclose',
'extpfeil',
'html',
'mathtools',
'mhchem',
'newcommand',
'noerrors',
Expand Down
62 changes: 58 additions & 4 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';


namespace ParseUtil {
Expand Down Expand Up @@ -104,7 +105,7 @@ namespace ParseUtil {
* @param {number} m The number.
* @return {string} The em dimension string.
*/
export function Em(m: number): string {
export function Em(m: number): string {
if (Math.abs(m) < .0006) {
return '0em';
}
Expand Down Expand Up @@ -352,6 +353,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 @@ -383,7 +418,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 @@ -450,6 +485,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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that you prefer to reduce indentation when possible, but the indentation sometimes has meaning. In this case, the function will produce one of two error messages, neither of which is more important than the other. The indentation of both shows that they are comparable alternatives. Leaving out the "else" would make the second be the "main" message and the first be a subordinate one. It makes the isMacro variable a break0out condition rather than a toggle that determines which of two equal things is being selected. This structure preserves the logic of the function better than having the two messages at different indentations, which gives the second a prominence it doesn't deserve.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you strongly object, I'd like to keep it as is.

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 @@ -505,8 +560,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 @@ -98,7 +98,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 @@ -1018,6 +1018,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 @@ -607,6 +607,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