Skip to content

Commit 7101270

Browse files
committed
Merge branch 'misc-fixes'
2 parents b7901ee + ccea021 commit 7101270

File tree

27 files changed

+1402
-133
lines changed

27 files changed

+1402
-133
lines changed

mathjax2/legacy/jax/element/MmlNode.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var MML = MathJax.ElementJax.mml;
33

44
var PROPERTY = [
5+
'texWithDelims',
56
'movesupsub',
67
'subsupOK',
78
'primes',
@@ -14,19 +15,21 @@
1415
'variantForm',
1516
'autoOP'
1617
];
18+
var RENAME = {
19+
texWithDelims: 'withDelims'
20+
};
1721

1822
MML.mbase.Augment({
1923
toMmlNode: function (factory) {
2024
var kind = this.type;
2125
if (kind === 'texatom') kind = 'TeXAtom';
22-
if (this.inferred) kind = 'inferredMrow';
2326
var node = this.nodeMake(factory, kind);
2427
if ("texClass" in this) node.texClass = this.texClass;
2528
return node;
2629
},
2730
nodeMake: function (factory,kind) {
2831
var node = factory.MML[kind]();
29-
var data = (this.data[0] && this.data[0].inferred ? this.data[0].data : this.data);
32+
var data = (this.data[0] && this.data[0].inferred && this.inferRow ? this.data[0].data : this.data);
3033
for (var i = 0, m = data.length; i < m; i++) {
3134
var child = data[i];
3235
if (child) node.appendChild(child.toMmlNode(factory));
@@ -62,7 +65,7 @@
6265
var name = PROPERTY[i];
6366
if (this[name] != null &&
6467
(this.defaults[name] == null || this.defaults[name] === MML.AUTO)) {
65-
node.setProperty(name, this[name]);
68+
node.setProperty(RENAME[name] || name, this[name]);
6669
}
6770
}
6871
}

mathjax3-ts/core/MmlTree/MmlNode.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
207207
public static defaults: PropertyList = {
208208
mathbackground: INHERIT,
209209
mathcolor: INHERIT,
210+
mathsize: INHERIT, // technically only for token elements, but <mstyle mathsize="..."> should
211+
// scale all spaces, fractions, etc.
210212
dir: INHERIT
211213
};
212214
/*
@@ -222,22 +224,6 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
222224
mpadded: {width: true, height: true, depth: true, lspace: true, voffset: true},
223225
mtable: {width: true, height: true, depth: true, align: true}
224226
},
225-
mtable: {
226-
mover: {align: true},
227-
munder: {align: true},
228-
munderover: {align: true},
229-
mtable: {
230-
align: true, rowalign: true, columnalign: true, groupalign: true,
231-
alignmentscope: true, columnwidth: true, width: true, rowspacing: true,
232-
columnspacing: true, rowlines: true, columnlines: true, frame: true,
233-
framespacing: true, equalrows: true, equalcolumns: true, displaystyle: true,
234-
side: true, minlabelspacing: true
235-
}
236-
},
237-
mtr: {
238-
mrow: {rowalign: true, columnalign: true, groupalign: true},
239-
mtable: {rowalign: true, columnalign: true, groupalign: true}
240-
},
241227
maligngroup: {
242228
mrow: {groupalign: true},
243229
mtable: {groupalign: true}
@@ -516,7 +502,7 @@ export abstract class AbstractMmlNode extends AbstractNode implements MmlNode {
516502
display: boolean = false, level: number = 0, prime: boolean = false) {
517503
let defaults = this.attributes.getAllDefaults();
518504
for (const key of Object.keys(attributes)) {
519-
if (key in defaults) {
505+
if (defaults.hasOwnProperty(key)) {
520506
let [node, value] = attributes[key];
521507
let noinherit = (AbstractMmlNode.noInherit[node] || {})[this.kind] || {};
522508
if (!noinherit[key]) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class MmlMath extends AbstractMmlLayoutNode {
9090
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
9191
display = (!!this.attributes.get('displaystyle') ||
9292
(!this.attributes.get('displaystyle') && this.attributes.get('display') === 'block'));
93+
this.attributes.setInherited('displaystyle', display);
9394
level = (this.attributes.get('scriptlevel') ||
9495
(this.constructor as typeof MmlMath).defaults['scriptlevel']) as number;
9596
super.setChildInheritedAttributes(attributes, display, level, prime);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ export class MmlMstyle extends AbstractMmlLayoutNode {
6565
level = parseInt(scriptlevel);
6666
}
6767
}
68-
let displaystyle = this.attributes.getExplicit('displaystyle') as string;
68+
let displaystyle = this.attributes.getExplicit('displaystyle') as boolean;
6969
if (displaystyle != null) {
70-
display = (displaystyle === 'true');
70+
display = (displaystyle === true);
7171
}
7272
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
7373
this.childNodes[0].setInheritedAttributes(attributes, display, level, prime);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export class MmlMtable extends AbstractMmlNode {
8484
}
8585
}
8686
display = !!(this.attributes.getExplicit('displaystyle') || this.attributes.getDefault('displaystyle'));
87-
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
8887
super.setChildInheritedAttributes(attributes, display, level, prime);
8988
}
9089

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export class MmlMtr extends AbstractMmlNode {
6464
.appendChild(child);
6565
}
6666
}
67-
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
6867
super.setChildInheritedAttributes(attributes, display, level, prime);
6968
}
7069

mathjax3-ts/output/chtml/FontData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class FontData {
197197
big_op_spacing1: .111,
198198
big_op_spacing2: .167,
199199
big_op_spacing3: .2,
200-
big_op_spacing4: .45, // .6, // better spacing for under arrows and braces
200+
big_op_spacing4: .6,
201201
big_op_spacing5: .1,
202202

203203
surd_height: .075,

mathjax3-ts/output/chtml/Wrapper.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ export const FONTSIZE: StringMap = {
5959
'249%': 'HG'
6060
};
6161

62+
export const SPACE: StringMap = {
63+
[LENGTHS.em(3/18)]: '1',
64+
[LENGTHS.em(4/18)]: '2',
65+
[LENGTHS.em(5/18)]: '3',
66+
};
67+
6268
/*
6369
* Needed to access node.style[id] using variable id
6470
*/
@@ -102,6 +108,8 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
102108
'mjx-box': {display: 'inline-block'},
103109
'mjx-block': {display: 'block'},
104110
'mjx-itable': {display: 'inline-table'},
111+
'mjx-row': {display: 'table-row'},
112+
'mjx-row > *': {display: 'table-cell'},
105113

106114
//
107115
// These don't have Wrapper subclasses, so add their styles here
@@ -304,24 +312,21 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
304312
if (this.bboxComputed) {
305313
return this.bbox;
306314
}
307-
let bbox = this.computeBBox();
308-
if (save) {
309-
this.bbox = bbox;
310-
this.bboxComputed = true;
311-
}
315+
const bbox = (save ? this.bbox : BBox.zero());
316+
this.computeBBox(bbox);
317+
this.bboxComputed = save;
312318
return bbox;
313319
}
314320

315321
/*
316-
* @return{BBox} The computed bounding box for the wrapped node
322+
* @param{BBox} bbox The bounding box to modify (either this.bbox, or an empty one)
317323
*/
318-
protected computeBBox() {
319-
const bbox = this.bbox.empty();
324+
protected computeBBox(bbox: BBox) {
325+
bbox.empty();
320326
for (const child of this.childNodes) {
321327
bbox.append(child.getBBox());
322328
}
323329
bbox.clean();
324-
return bbox;
325330
}
326331

327332
/*******************************************************************/
@@ -405,7 +410,8 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
405410
let attributes = this.node.attributes;
406411
let scriptlevel = Math.min(attributes.get('scriptlevel') as number, 2);
407412
let fontsize = attributes.get('fontsize');
408-
let mathsize = (parent && !this.node.isToken ? parent : this).node.attributes.get('mathsize');
413+
let mathsize = (this.node.isToken || this.node.isKind('mstyle') ?
414+
attributes.get('mathsize') : attributes.getInherited('mathsize'));
409415
//
410416
// If scriptsize is non-zero, set scale based on scriptsizemultiplier
411417
//
@@ -507,15 +513,25 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
507513
* Set the (relative) scaling factor for the node
508514
*/
509515
protected handleScale() {
510-
const scale = (Math.abs(this.bbox.rscale - 1) < .001 ? 1 : this.bbox.rscale);
511-
if (this.chtml && scale !== 1) {
516+
this.setScale(this.chtml, this.bbox.rscale);
517+
}
518+
519+
/*
520+
* @param{HTMLElement} chtml The HTML node to scale
521+
* @param{number} rscale The relatie scale to apply
522+
* @return{HTMLElement} The HTML node (for chaining)
523+
*/
524+
setScale(chtml: HTMLElement, rscale: number) {
525+
const scale = (Math.abs(rscale - 1) < .001 ? 1 : rscale);
526+
if (chtml && scale !== 1) {
512527
const size = this.percent(scale);
513528
if (FONTSIZE[size]) {
514-
this.chtml.setAttribute('size', FONTSIZE[size]);
529+
chtml.setAttribute('size', FONTSIZE[size]);
515530
} else {
516-
this.chtml.style.fontSize = size;
531+
chtml.style.fontSize = size;
517532
}
518533
}
534+
return chtml;
519535
}
520536

521537
/*
@@ -524,7 +540,12 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
524540
*/
525541
protected handleSpace() {
526542
if (this.bbox.L) {
527-
this.chtml.setAttribute('space', (this.bbox.L * 18 - 2).toString());
543+
const space = this.em(this.bbox.L);
544+
if (SPACE[space]) {
545+
this.chtml.setAttribute('space', SPACE[space]);
546+
} else {
547+
this.chtml.style.marginLeft = space;
548+
}
528549
}
529550
}
530551

@@ -624,7 +645,7 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
624645
public drawBBox() {
625646
const bbox = this.getBBox();
626647
const box = this.html('mjx-box', {style: {
627-
opacity: .25, 'margin-left': this.em(-bbox.w)
648+
opacity: .25, 'margin-left': this.em(-bbox.w - bbox.R)
628649
}}, [
629650
this.html('mjx-box', {style: {
630651
height: this.em(bbox.h),
@@ -640,7 +661,7 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
640661
}})
641662
]);
642663
const node = this.chtml || this.parent.chtml;
643-
node.appendChild(box);
664+
node.parentNode.appendChild(box);
644665
node.style.backgroundColor = '#FFEE00';
645666
}
646667

mathjax3-ts/output/chtml/Wrappers.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import {CHTMLmrow, CHTMLinferredMrow} from './Wrappers/mrow.js';
3030
import {CHTMLmfrac} from './Wrappers/mfrac.js';
3131
import {CHTMLmsqrt} from './Wrappers/msqrt.js';
3232
import {CHTMLmroot} from './Wrappers/mroot.js';
33+
import {CHTMLmsub, CHTMLmsup, CHTMLmsubsup} from './Wrappers/msubsup.js';
34+
import {CHTMLmover, CHTMLmunder, CHTMLmunderover} from './Wrappers/munderover.js';
35+
import {CHTMLmtable} from './Wrappers/mtable.js';
36+
import {CHTMLmtr, CHTMLmlabeledtr} from './Wrappers/mtr.js';
37+
import {CHTMLmtd} from './Wrappers/mtd.js';
3338
import {CHTMLsemantics, CHTMLannotation, CHTMLannotationXML, CHTMLxml} from './Wrappers/semantics.js';
3439
import {CHTMLTeXAtom} from './Wrappers/TeXAtom.js';
3540
import {CHTMLTextNode} from './Wrappers/TextNode.js';
@@ -44,6 +49,16 @@ export const CHTMLWrappers: {[kind: string]: typeof CHTMLWrapper} = {
4449
[CHTMLmfrac.kind]: CHTMLmfrac,
4550
[CHTMLmsqrt.kind]: CHTMLmsqrt,
4651
[CHTMLmroot.kind]: CHTMLmroot,
52+
[CHTMLmsub.kind]: CHTMLmsub,
53+
[CHTMLmsup.kind]: CHTMLmsup,
54+
[CHTMLmsubsup.kind]: CHTMLmsubsup,
55+
[CHTMLmunder.kind]: CHTMLmunder,
56+
[CHTMLmover.kind]: CHTMLmover,
57+
[CHTMLmunderover.kind]: CHTMLmunderover,
58+
[CHTMLmtable.kind]: CHTMLmtable,
59+
[CHTMLmtr.kind]: CHTMLmtr,
60+
[CHTMLmlabeledtr.kind]: CHTMLmlabeledtr,
61+
[CHTMLmtd.kind]: CHTMLmtd,
4762
[CHTMLsemantics.kind]: CHTMLsemantics,
4863
[CHTMLannotation.kind]: CHTMLannotation,
4964
[CHTMLannotationXML.kind]: CHTMLannotationXML,

mathjax3-ts/output/chtml/Wrappers/TeXAtom.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class CHTMLTeXAtom extends CHTMLWrapper {
4343
// Center VCENTER atoms vertically
4444
//
4545
if (this.node.texClass === TEXCLASS.VCENTER) {
46-
const bbox = super.computeBBox(); // get unmodified bbox of children
46+
const bbox = this.childNodes[0].getBBox(); // get unmodified bbox of children
4747
const {h, d} = bbox;
4848
const a = this.font.params.axis_height;
4949
const dh = ((h + d) / 2 + a) - h; // new height minus old height
@@ -54,8 +54,8 @@ export class CHTMLTeXAtom extends CHTMLWrapper {
5454
/*
5555
* @override
5656
*/
57-
public computeBBox() {
58-
const bbox = super.computeBBox();
57+
public computeBBox(bbox: BBox) {
58+
super.computeBBox(bbox);
5959
//
6060
// Center VCENTER atoms vertically
6161
//
@@ -66,7 +66,6 @@ export class CHTMLTeXAtom extends CHTMLWrapper {
6666
bbox.h += dh;
6767
bbox.d += dh;
6868
}
69-
return bbox;
7069
}
7170

7271
}

0 commit comments

Comments
 (0)