Skip to content

Commit 4afd1e9

Browse files
committed
Merge branch 'mathml-spacing' into alpha
2 parents 268bce7 + d6df01d commit 4afd1e9

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

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

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

3030
/*****************************************************************/
3131
/*
@@ -60,9 +60,10 @@ export class MmlMo extends AbstractMmlTokenNode {
6060
};
6161

6262
/*
63-
* Unicode ranges and their default TeX classes
63+
* Unicode ranges and their default TeX classes and MathML spacing
6464
*/
65-
public static RANGES: RangeDef[] = RANGES;
65+
public static RANGES = RANGES;
66+
public static MMLSPACING = MMLSPACING;
6667

6768
/*
6869
* The Operator Dictionary.
@@ -164,8 +165,7 @@ export class MmlMo extends AbstractMmlTokenNode {
164165
* @override
165166
*/
166167
public hasSpacingAttributes() {
167-
return !!this.attributes.getExplicit('form') ||
168-
this.attributes.isSet('lspace') ||
168+
return this.attributes.isSet('lspace') ||
169169
this.attributes.isSet('rspace');
170170
}
171171

@@ -177,10 +177,6 @@ export class MmlMo extends AbstractMmlTokenNode {
177177
public setTeXclass(prev: MmlNode): MmlNode {
178178
let {form, lspace, rspace, fence} = this.attributes.getList('form', 'lspace', 'rspace', 'fence') as
179179
{form: string, lspace: string, rspace: string, fence: string};
180-
if (this.hasSpacingAttributes()) {
181-
this.texClass = TEXCLASS.NONE;
182-
return this;
183-
}
184180
if (fence && this.texClass === TEXCLASS.REL) {
185181
if (form === 'prefix') {
186182
this.texClass = TEXCLASS.OPEN;
@@ -276,8 +272,9 @@ export class MmlMo extends AbstractMmlTokenNode {
276272
let range = this.getRange(mo);
277273
if (range) {
278274
this.texClass = range[2];
279-
this.lspace = (def[0] + 1) / 18;
280-
this.rspace = (def[1] + 1) / 18;
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;
281278
}
282279
}
283280
}

mathjax3-ts/core/MmlTree/OperatorDictionary.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ export const RANGES: RangeDef[] = [
102102
[0x1D400, 0x1D7FF, TEXCLASS.ORD, 'MathAlphabets']
103103
];
104104

105+
/*
106+
* The default MathML spacing for the various TeX classes.
107+
*/
108+
export const MMLSPACING = [
109+
[0, 0], // ORD
110+
[1, 2], // OP
111+
[3, 3], // BIN
112+
[4, 4], // REL
113+
[0, 0], // OPEN
114+
[0, 0], // CLOSE
115+
[0, 3] // PUNCT
116+
];
117+
105118
/*
106119
* The operator dictionary, with sections for the three forms: prefix, postfix, and infix
107120
*/

mathjax3-ts/output/chtml/Wrapper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ export class CHTMLWrapper<N, T, D> extends AbstractWrapper<MmlNode, CHTMLWrapper
516516
const isTop = this.isTopEmbellished();
517517
const hasSpacing = this.node.hasSpacingAttributes();
518518
if (this.CHTML.options.mathmlSpacing || hasSpacing) {
519-
console.log(this.node.attributes);
520519
isTop && this.getMathMLSpacing();
521520
} else {
522521
this.getTeXSpacing(isTop, hasSpacing);

mathjax3-ts/util/lengths.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,21 @@ export const MATHSPACE: {[name: string]: number} = {
7979

8080

8181
/*
82-
* @param{Property} length A dimension (giving number and units) to be converted to ems
83-
* @param{number} size The default size of the dimension (for percentage values)
84-
* @param{number} scale The current scaling factor (to handle absolute units)
85-
* @return{number} The dimension converted to ems
82+
* @param{string|number} length A dimension (giving number and units) to be converted to ems
83+
* @param{number} size The default size of the dimension (for percentage values)
84+
* @param{number} scale The current scaling factor (to handle absolute units)
85+
* @return{number} The dimension converted to ems
8686
*/
87-
export function length2em(length: string, size: number = 0, scale: number = 1, em: number = 16) {
87+
export function length2em(length: string | number, size: number = 0, scale: number = 1, em: number = 16) {
88+
if (typeof length !== 'string') {
89+
length = String(length);
90+
}
8891
if (length === '' || length == null) {
8992
return size;
9093
}
9194
if (MATHSPACE[length]) {
9295
return MATHSPACE[length];
9396
}
94-
9597
let match = length.match(/^\s*([-+]?(?:\.\d+|\d+(?:\.\d*)?))?(pt|em|ex|mu|px|pc|in|mm|cm|%)?/);
9698
if (!match) {
9799
return size;

0 commit comments

Comments
 (0)