Skip to content

Commit 3085eb7

Browse files
authored
Merge branch 'master' into maction
2 parents 7d0f80e + 05bcf4e commit 3085eb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3033
-3938
lines changed

main.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
import {MathJax} from "mathjax3/mathjax.js";
2-
export {MathJax} from "mathjax3/mathjax.js";
1+
import {MathJax} from './mathjax3/mathjax.js';
32

4-
import {TeX} from "mathjax3/input/tex.js";
5-
import {RegisterHTMLHandler} from "mathjax3/handlers/html.js";
6-
import {chooseAdaptor} from "mathjax3/adaptors/chooseAdaptor.js";
7-
import {CHTML} from "mathjax3/output/chtml.js";
3+
import {TeX} from './mathjax3/input/tex.js';
4+
import {RegisterHTMLHandler} from './mathjax3/handlers/html.js';
5+
import {chooseAdaptor} from './mathjax3/adaptors/chooseAdaptor.js';
6+
import {CHTML} from './mathjax3/output/chtml.js';
87

9-
RegisterHTMLHandler(chooseAdaptor());
8+
const adaptor = chooseAdaptor();
9+
RegisterHTMLHandler(adaptor);
1010

11-
let html = MathJax.document("<html></html>", {
11+
const html = MathJax.document('<html></html>', {
1212
InputJax: new TeX(),
1313
OutputJax: new CHTML()
1414
});
1515

16-
MathJax.handleRetriesFor(function () {
16+
MathJax.handleRetriesFor(() => {
1717

1818
html.TestMath(process.argv[3] || '').compile().typeset();
1919
let math = html.math.pop();
20-
console.log(math.typeset.outerHTML);
20+
console.log(adaptor.outerHTML(math.typesetRoot));
2121

22-
}).catch(err => {
23-
console.log(err.message);
24-
console.log(err.stack.replace(/\n.*\/system\.js:(.|\n)*/,""));
25-
});
22+
}).catch(err => console.log(err.stack));
1.09 KB
Binary file not shown.
1.11 KB
Binary file not shown.

mathjax3-ts/adaptors/chooseAdaptor.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,17 @@
2121
* @author [email protected] (Davide Cervone)
2222
*/
2323

24-
import {jsdomAdaptor} from './jsdomAdaptor.js';
24+
import {liteAdaptor, LiteAdaptor} from './liteAdaptor.js';
2525
import {browserAdaptor} from './browserAdaptor.js';
26-
27-
/*
28-
* Declare the global variables used here
29-
*/
30-
declare var System: {nodeRequire: Function};
31-
declare function require(file: string): Object;
26+
import {HTMLAdaptor} from './HTMLAdaptor.js';
3227

3328
let choose;
3429

3530
try {
3631
document; // errors if not in browser
3732
choose = browserAdaptor;
3833
} catch(e) {
39-
const JSDOM = (typeof(System) === 'undefined' ? require : System.nodeRequire)('jsdom').JSDOM;
40-
choose = function () {
41-
return jsdomAdaptor(JSDOM);
42-
}
34+
choose = liteAdaptor;
4335
}
4436

4537
/*

mathjax3-ts/adaptors/lite/Parser.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import {AttributeData} from '../../core/DOMAdaptor.js';
2525
import {MinHTMLAdaptor, MinDOMParser} from '../HTMLAdaptor.js';
26-
import {Entities} from '../../util/Entities.js';
26+
import * as Entities from '../../util/Entities.js';
2727
import {LiteDocument} from './Document.js';
2828
import {LiteElement} from './Element.js';
2929
import {LiteText, LiteComment} from './Text.js';
@@ -110,18 +110,6 @@ export class LiteParser implements MinDOMParser<LiteDocument> {
110110
scheme: true
111111
};
112112

113-
/*
114-
* The entity translator object
115-
*/
116-
protected entities: Entities;
117-
118-
/*
119-
* @constructor
120-
*/
121-
constructor() {
122-
this.entities = new Entities({loadMissingEntities: false});
123-
}
124-
125113
/*
126114
* @override
127115
*/
@@ -160,7 +148,7 @@ export class LiteParser implements MinDOMParser<LiteDocument> {
160148
* @return{LiteText} The text element
161149
*/
162150
protected addText(adaptor: LiteAdaptor, node: LiteElement, text: string) {
163-
text = this.entities.translate(text);
151+
text = Entities.translate(text);
164152
return adaptor.append(node, adaptor.text(text)) as LiteText;
165153
}
166154

@@ -246,7 +234,7 @@ export class LiteParser implements MinDOMParser<LiteDocument> {
246234
let [space, name, v1, v2, v3] = attributes.splice(0,5);
247235
let value = v1 || v2 || v3 || '';
248236
if (!CDATA_ATTR[name]) {
249-
value = this.entities.translate(value);
237+
value = Entities.translate(value);
250238
}
251239
adaptor.setAttribute(node, name, value);
252240
}

mathjax3-ts/adaptors/liteAdaptor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export class LiteAdaptor extends AbstractDOMAdaptor<LiteElement, LiteText, LiteD
306306
const text = new LiteText(node.value.slice(n));
307307
node.value = node.value.slice(0, n);
308308
node.parent.children.splice(this.childIndex(node) + 1, 0, text);
309+
text.parent = node.parent;
309310
return text;
310311
}
311312

mathjax3-ts/core/MmlTree/MML.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import {MmlMtd} from './MmlNodes/mtd.js';
5555
import {MmlMaligngroup} from './MmlNodes/maligngroup.js';
5656
import {MmlMalignmark} from './MmlNodes/malignmark.js';
5757

58+
import {MmlMglyph} from './MmlNodes/mglyph.js';
59+
5860
import {MmlSemantics, MmlAnnotation, MmlAnnotationXML} from './MmlNodes/semantics.js';
5961

6062
import {TeXAtom} from './MmlNodes/TeXAtom.js';
@@ -109,6 +111,8 @@ export let MML: {[kind: string]: MmlNodeClass} = {
109111
[MmlMaligngroup.prototype.kind]: MmlMaligngroup,
110112
[MmlMalignmark.prototype.kind]: MmlMalignmark,
111113

114+
[MmlMglyph.prototype.kind]: MmlMglyph,
115+
112116
[MmlSemantics.prototype.kind]: MmlSemantics,
113117
[MmlAnnotation.prototype.kind]: MmlAnnotation,
114118
[MmlAnnotationXML.prototype.kind]: MmlAnnotationXML,

mathjax3-ts/core/MmlTree/MmlNode.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ export interface MmlNode extends Node {
140140
* @return {string} The spacing to use before this element (one of TEXSPACELENGTH array above)
141141
*/
142142
texSpacing(): string;
143+
/*
144+
* @return {boolean} The core mo element has an explicit 'form', 'lspace', or 'rspace' attribute
145+
*/
146+
hasSpacingAttributes(): boolean;
143147

144148
/*
145149
* Sets the nodes inherited attributes, and pushes them to the nodes children.
@@ -484,6 +488,13 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
484488
return TEXSPACELENGTH[Math.abs(space)];
485489
}
486490

491+
/*
492+
* @return {boolean} The core mo element has an explicit 'form' attribute
493+
*/
494+
public hasSpacingAttributes() {
495+
return this.isEmbellished && this.coreMO().hasSpacingAttributes();
496+
}
497+
487498
/*
488499
* Sets the inherited propertis for this node, and pushes inherited properties to the children
489500
*
@@ -939,6 +950,13 @@ export abstract class AbstractMmlEmptyNode extends AbstractEmptyNode implements
939950
return 0;
940951
}
941952

953+
/*
954+
* @return {boolean} The core mo element has an explicit 'form' attribute
955+
*/
956+
public hasSpacingAttributes() {
957+
return false;
958+
}
959+
942960
/*
943961
* return {Attributes} No attributes, so don't store one
944962
*/

mathjax3-ts/core/MmlTree/MmlNodes/mglyph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {AbstractMmlTokenNode, TEXCLASS} from '../MmlNode.js';
2929
* Implements the MmlMglyph node class (subclass of AbstractMmlTokenNode)
3030
*/
3131

32-
export class MmlMi extends AbstractMmlTokenNode {
32+
export class MmlMglyph extends AbstractMmlTokenNode {
3333
public static defaults: PropertyList = {
3434
...AbstractMmlTokenNode.defaults,
3535
alt: '',

mathjax3-ts/core/MmlTree/MmlNodes/mo.ts

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import {PropertyList} from '../../Tree/Node.js';
2525
import {AbstractMmlTokenNode, MmlNode, AttributeList, TEXCLASS} from '../MmlNode.js';
2626
import {MmlMrow} from './mrow.js';
27-
import {OperatorList, OPTABLE, RangeDef, RANGES} from '../OperatorDictionary.js';
27+
import {MmlMover, MmlMunder, MmlMunderover} from './munderover.js';
28+
import {OperatorList, OPTABLE, RangeDef, RANGES, MMLSPACING} from '../OperatorDictionary.js';
2829

2930
/*****************************************************************/
3031
/*
@@ -59,21 +60,10 @@ export class MmlMo extends AbstractMmlTokenNode {
5960
};
6061

6162
/*
62-
* The sizes of the various lspace and rspace values in the operator table
63+
* Unicode ranges and their default TeX classes and MathML spacing
6364
*/
64-
public static SPACE = [
65-
'0em',
66-
'0.1111em',
67-
'0.1667em',
68-
'0.2222em',
69-
'0.2667em',
70-
'0.3333em'
71-
];
72-
73-
/*
74-
* Unicode ranges and their default TeX classes
75-
*/
76-
public static RANGES: RangeDef[] = RANGES;
65+
public static RANGES = RANGES;
66+
public static MMLSPACING = MMLSPACING;
7767

7868
/*
7969
* The Operator Dictionary.
@@ -85,6 +75,12 @@ export class MmlMo extends AbstractMmlTokenNode {
8575
*/
8676
public texClass = TEXCLASS.REL;
8777

78+
/*
79+
* The default MathML spacing on the left and right
80+
*/
81+
public lspace = 5/18;
82+
public rspace = 5/18;
83+
8884
/*
8985
* @return {string} The mo kind
9086
*/
@@ -138,15 +134,49 @@ export class MmlMo extends AbstractMmlTokenNode {
138134
return (parent.isToken ? (parent as AbstractMmlTokenNode).getText() : '');
139135
}
140136

137+
/*
138+
* @override
139+
*/
140+
public hasSpacingAttributes() {
141+
return this.attributes.isSet('lspace') ||
142+
this.attributes.isSet('rspace');
143+
}
144+
145+
/*
146+
* @return{boolean} True is this mo is an accent in an munderover construction
147+
*/
148+
get isAccent() {
149+
let accent = false;
150+
const node = this.coreParent();
151+
if (node) {
152+
const key = (node.isKind('mover') ?
153+
((node.childNodes[(node as MmlMover).over] as MmlNode).coreMO() ?
154+
'accent' : '') :
155+
node.isKind('munder') ?
156+
((node.childNodes[(node as MmlMunder).under] as MmlNode).coreMO() ?
157+
'accentunder' : '') :
158+
node.isKind('munderover') ?
159+
(this === (node.childNodes[(node as MmlMunderover).over] as MmlNode).coreMO() ?
160+
'accent' :
161+
this === (node.childNodes[(node as MmlMunderover).under] as MmlNode).coreMO() ?
162+
'accentunder' : '') :
163+
'');
164+
if (key) {
165+
const value = node.attributes.getExplicit(key);
166+
accent = (value !== undefined ? accent : this.attributes.get('accent')) as boolean;
167+
}
168+
}
169+
return accent;
170+
}
171+
141172
/*
142173
* Produce the texClass based on the operator dictionary values
143174
*
144175
* @override
145176
*/
146-
public setTeXclass(prev: MmlNode) {
177+
public setTeXclass(prev: MmlNode): MmlNode {
147178
let {form, lspace, rspace, fence} = this.attributes.getList('form', 'lspace', 'rspace', 'fence') as
148179
{form: string, lspace: string, rspace: string, fence: string};
149-
// if (this.useMMLspacing) {this.texClass = TEXCLASS.NONE; return this}
150180
if (fence && this.texClass === TEXCLASS.REL) {
151181
if (form === 'prefix') {
152182
this.texClass = TEXCLASS.OPEN;
@@ -227,7 +257,7 @@ export class MmlMo extends AbstractMmlTokenNode {
227257
display: boolean = false, level: number = 0, prime: boolean = false) {
228258
super.setInheritedAttributes(attributes, display, level, prime);
229259
let mo = this.getText();
230-
let [form1, form2, form3] = this.getForms();
260+
let [form1, form2, form3] = this.handleExplicitForm(this.getForms());
231261
this.attributes.setInherited('form', form1);
232262
let OPTABLE = (this.constructor as typeof MmlMo).OPTABLE;
233263
let def = OPTABLE[form1][mo] || OPTABLE[form2][mo] || OPTABLE[form3][mo];
@@ -236,10 +266,15 @@ export class MmlMo extends AbstractMmlTokenNode {
236266
for (const name of Object.keys(def[3] || {})) {
237267
this.attributes.setInherited(name, def[3][name]);
238268
}
269+
this.lspace = (def[0] + 1) / 18;
270+
this.rspace = (def[1] + 1) / 18;
239271
} else {
240272
let range = this.getRange(mo);
241273
if (range) {
242274
this.texClass = range[2];
275+
const spacing = (this.constructor as typeof MmlMo).MMLSPACING[range[2]];
276+
this.lspace = (spacing[0] + 1) / 18;
277+
this.rspace = (spacing[1] + 1) / 18;
243278
}
244279
}
245280
}
@@ -269,6 +304,18 @@ export class MmlMo extends AbstractMmlTokenNode {
269304
return ['infix', 'prefix', 'postfix'];
270305
}
271306

307+
/*
308+
* @param{string[]} forms The three forms in the default order they are to be tested
309+
* @return{string[]} The forms in the new order, if there is an explicit form attribute
310+
*/
311+
protected handleExplicitForm(forms: string[]) {
312+
if (this.attributes.isSet('form')) {
313+
const form = this.attributes.get('form') as string;
314+
forms = [form].concat(forms.filter(name => (name !== form)));
315+
}
316+
return forms;
317+
}
318+
272319
/*
273320
* @param {string} mo The character to look up in the range table
274321
* @return {RangeDef} The unicode range in which the character falls, or null

0 commit comments

Comments
 (0)