Skip to content

Commit 43db147

Browse files
committed
Make changes requested by code review. Also move copyMml() to MmlNode, since it is useful in order situations, as well.
1 parent 5455596 commit 43db147

13 files changed

Lines changed: 437 additions & 171 deletions

File tree

components/src/dependencies.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const dependencies = {
2828
'[tex]/textmacros': ['input/tex-base'],
2929
'[tex]/unicode': ['input/tex-base'],
3030
'[tex]/verb': ['input/tex-base'],
31-
'[tex]/numcases': ['[tex]/empheq'],
31+
'[tex]/cases': ['[tex]/empheq'],
3232
'[tex]/empheq': ['input/tex-base', '[tex]/ams']
3333
};
3434

@@ -61,7 +61,7 @@ const allPackages = [
6161
'[tex]/textmacros',
6262
'[tex]/unicode',
6363
'[tex]/verb',
64-
'[tex]/numcases',
64+
'[tex]/cases',
6565
'[tex]/empheq'
6666
];
6767

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": "input/tex/extensions/cases",
3+
"targets": ["input/tex/cases"]
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './lib/cases.js';

components/src/input/tex/extensions/numcases/webpack.config.js renamed to components/src/input/tex/extensions/cases/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const PACKAGE = require('../../../../../webpack.common.js');
22

33
module.exports = PACKAGE(
4-
'numcases', // the package to build
4+
'cases', // the package to build
55
'../../../../../js', // location of the compiled js files
66
[ // packages to link to (relative to Mathjax components)
77
'components/src/input/tex-base/lib',

components/src/input/tex/extensions/numcases/build.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

components/src/input/tex/extensions/numcases/numcases.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

components/src/source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const source = {
3232
'[tex]/textmacros': `${src}/input/tex/extensions/textmacros/textmacros.js`,
3333
'[tex]/unicode': `${src}/input/tex/extensions/unicode/unicode.js`,
3434
'[tex]/verb': `${src}/input/tex/extensions/verb/verb.js`,
35-
'[tex]/numcases': `${src}/input/tex/extensions/numcases/numcases.js`,
35+
'[tex]/cases': `${src}/input/tex/extensions/cases/cases.js`,
3636
'[tex]/empheq': `${src}/input/tex/extensions/empheq/empheq.js`,
3737
'input/mml': `${src}/input/mml/mml.js`,
3838
'input/mml/entities': `${src}/input/mml/entities/entities.js`,

ts/core/MmlTree/MmlNode.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export type MMLNODE = MmlNode | TextNode | XMLNode;
8787
*/
8888

8989
export interface MmlNode extends Node {
90+
9091
/**
9192
* Test various properties of MathML nodes
9293
*/
@@ -95,21 +96,25 @@ export interface MmlNode extends Node {
9596
readonly isSpacelike: boolean;
9697
readonly linebreakContainer: boolean;
9798
readonly hasNewLine: boolean;
99+
98100
/**
99101
* The expected number of children (-1 means use inferred mrow)
100102
*/
101103
readonly arity: number;
102104
readonly isInferred: boolean;
105+
103106
/**
104107
* Get the parent node (skipping inferred mrows and
105108
* other nodes marked as notParent)
106109
*/
107110
readonly Parent: MmlNode;
108111
readonly notParent: boolean;
112+
109113
/**
110114
* The actual parent in the tree
111115
*/
112116
parent: MmlNode;
117+
113118
/**
114119
* values needed for TeX spacing computations
115120
*/
@@ -127,16 +132,19 @@ export interface MmlNode extends Node {
127132
* core <mo> node. For non-embellished nodes, the original node.
128133
*/
129134
core(): MmlNode;
135+
130136
/**
131137
* @return {MmlNode} For embellished operators, the core <mo> element (at whatever
132138
* depth). For non-embellished nodes, the original node itself.
133139
*/
134140
coreMO(): MmlNode;
141+
135142
/**
136143
* @return {number} For embellished operators, the index of the child node containing
137144
* the core <mo>. For non-embellished nodes, 0.
138145
*/
139146
coreIndex(): number;
147+
140148
/**
141149
* @return {number} The index of this node in its parent's childNodes array.
142150
*/
@@ -149,10 +157,12 @@ export interface MmlNode extends Node {
149157
* in the tree (usually, either the last child, or the node itself)
150158
*/
151159
setTeXclass(prev: MmlNode): MmlNode;
160+
152161
/**
153162
* @return {string} The spacing to use before this element (one of TEXSPACELENGTH array above)
154163
*/
155164
texSpacing(): string;
165+
156166
/**
157167
* @return {boolean} The core mo element has an explicit 'form', 'lspace', or 'rspace' attribute
158168
*/
@@ -201,10 +211,12 @@ export interface MmlNode extends Node {
201211
*/
202212

203213
export interface MmlNodeClass extends NodeClass {
214+
204215
/**
205216
* The list of default attribute values for nodes of this class
206217
*/
207218
defaults?: PropertyList;
219+
208220
/**
209221
* An MmlNode takes a NodeFactory (so it can create additional nodes as needed), a list
210222
* of attributes, and an array of children and returns the desired MmlNode with
@@ -216,6 +228,7 @@ export interface MmlNodeClass extends NodeClass {
216228
* @param {MmlNode[]} children The initial child nodes (more can be added later)
217229
*/
218230
new (factory: MmlFactory, attributes?: PropertyList, children?: MmlNode[]): MmlNode;
231+
219232
}
220233

221234

@@ -237,6 +250,7 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
237250
// scale all spaces, fractions, etc.
238251
dir: INHERIT
239252
};
253+
240254
/**
241255
* This lists properties that do NOT get inherited between specific kinds
242256
* of nodes. The outer keys are the node kinds that are being inherited FROM,
@@ -285,6 +299,7 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
285299
* The TeX class for the preceding node
286300
*/
287301
public prevClass: number = null;
302+
288303
/**
289304
* The scriptlevel of the preceding node
290305
*/
@@ -299,10 +314,12 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
299314
* Child nodes are MmlNodes (special case of Nodes).
300315
*/
301316
public childNodes: MmlNode[];
317+
302318
/**
303319
* The parent is an MmlNode
304320
*/
305321
public parent: MmlNode;
322+
306323
/**
307324
* The node factory is an MmlFactory
308325
*/
@@ -330,6 +347,36 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
330347
this.attributes.setList(attributes);
331348
}
332349

350+
/**
351+
* @override
352+
*
353+
* @param {boolean} keepIds True to copy id attributes, false to skip them.
354+
*/
355+
public copy(keepIds: boolean = false): AbstractMmlNode {
356+
const node = this.factory.create(this.kind) as AbstractMmlNode;
357+
node.properties = {...this.properties};
358+
if (this.attributes) {
359+
const attributes = this.attributes.getAllAttributes();
360+
for (const name of Object.keys(attributes)) {
361+
if (name !== 'id' || keepIds) {
362+
node.attributes.set(name, attributes[name]);
363+
}
364+
}
365+
}
366+
if (this.childNodes && this.childNodes.length) {
367+
let children = this.childNodes as MmlNode[];
368+
if (children.length === 1 && children[0].isInferred) {
369+
children = children[0].childNodes as MmlNode[];
370+
}
371+
for (const child of children) {
372+
if (child) {
373+
node.appendChild(child.copy() as MmlNode);
374+
}
375+
}
376+
}
377+
return node;
378+
}
379+
333380
/**
334381
* The TeX class for this node
335382
*/
@@ -1150,6 +1197,13 @@ export class TextNode extends AbstractMmlEmptyNode {
11501197
return this;
11511198
}
11521199

1200+
/**
1201+
* @override
1202+
*/
1203+
public copy() {
1204+
return (this.factory.create(this.kind) as TextNode).setText(this.getText());
1205+
}
1206+
11531207
/**
11541208
* Just use the text
11551209
*/
@@ -1208,6 +1262,13 @@ export class XMLNode extends AbstractMmlEmptyNode {
12081262
return this.adaptor.outerHTML(this.xml);
12091263
}
12101264

1265+
/**
1266+
* @override
1267+
*/
1268+
public copy(): XMLNode {
1269+
return (this.factory.create(this.kind) as XMLNode).setXML(this.adaptor.clone(this.xml));
1270+
}
1271+
12111272
/**
12121273
* Just indicate that this is XML data
12131274
*/

ts/core/Tree/Node.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export interface Node {
102102
*/
103103
childIndex(child: Node): number;
104104

105+
/**
106+
* Make a deep copy of the node (but with no parent).
107+
*/
108+
copy(): Node;
109+
105110
/**
106111
* @param {string} kind The kind of nodes to be located in the tree
107112
* @return {Node[]} An array of nodes that are children (at any depth) of the given kind
@@ -264,6 +269,18 @@ export abstract class AbstractNode implements Node {
264269
}
265270

266271

272+
/**
273+
* @override
274+
*/
275+
public copy() {
276+
const node = (this as AbstractNode).factory.create(this.kind) as AbstractNode;
277+
node.properties = {...this.properties};
278+
for (const child of this.childNodes || []) {
279+
if (child) node.appendChild(child.copy());
280+
}
281+
return node;
282+
}
283+
267284
/**
268285
* @override
269286
*/

ts/input/tex/AllPackages.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import './boldsymbol/BoldsymbolConfiguration.js';
3030
import './braket/BraketConfiguration.js';
3131
import './bussproofs/BussproofsConfiguration.js';
3232
import './cancel/CancelConfiguration.js';
33+
import './cases/CasesConfiguration.js';
3334
import './color/ColorConfiguration.js';
3435
import './colorv2/ColorV2Configuration.js';
3536
import './configmacros/ConfigMacrosConfiguration.js';
37+
import './empheq/EmpheqConfiguration.js';
3638
import './enclose/EncloseConfiguration.js';
3739
import './extpfeil/ExtpfeilConfiguration.js';
3840
import './html/HtmlConfiguration.js';
@@ -45,8 +47,6 @@ import './tagformat/TagFormatConfiguration.js';
4547
import './textmacros/TextMacrosConfiguration.js';
4648
import './unicode/UnicodeConfiguration.js';
4749
import './verb/VerbConfiguration.js';
48-
import './numcases/NumcasesConfiguration.js';
49-
import './empheq/EmpheqConfiguration.js';
5050

5151
declare const MathJax: any;
5252
if (typeof MathJax !== 'undefined' && MathJax.loader) {
@@ -59,8 +59,10 @@ if (typeof MathJax !== 'undefined' && MathJax.loader) {
5959
'[tex]/braket',
6060
'[tex]/bussproofs',
6161
'[tex]/cancel',
62+
'[tex]/cases',
6263
'[tex]/color',
6364
'[tex]/colorv2',
65+
'[tex]/empheq',
6466
'[tex]/enclose',
6567
'[tex]/extpfeil',
6668
'[tex]/html',
@@ -71,8 +73,6 @@ if (typeof MathJax !== 'undefined' && MathJax.loader) {
7173
'[tex]/physics',
7274
'[tex]/unicode',
7375
'[tex]/verb',
74-
'[tex]/numcases',
75-
'[tex]/empheq',
7676
'[tex]/configmacros',
7777
'[tex]/tagformat',
7878
'[tex]/textmacros'
@@ -89,7 +89,9 @@ export const AllPackages: string[] = [
8989
'braket',
9090
'bussproofs',
9191
'cancel',
92+
'cases',
9293
'color',
94+
'empheq',
9395
'enclose',
9496
'extpfeil',
9597
'html',
@@ -99,8 +101,6 @@ export const AllPackages: string[] = [
99101
'noundefined',
100102
'unicode',
101103
'verb',
102-
'numcases',
103-
'empheq',
104104
'configmacros',
105105
'tagformat',
106106
'textmacros'

0 commit comments

Comments
 (0)