Skip to content

Commit ef40f78

Browse files
committed
Merge branch 'math-tag-support' into master
2 parents 83f5c77 + efd937e commit ef40f78

File tree

12 files changed

+237
-25
lines changed

12 files changed

+237
-25
lines changed

mathjax3-ts/output/chtml/BBox.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class BBox {
6565
public L: number; // extra space on the left
6666
public R: number; // extra space on the right
6767
public pwidth: string; // percentage width (for tables)
68+
public ic: number;
6869

6970
/*
7071
* @return{BBox} A BBox initialized to zeros
@@ -91,7 +92,7 @@ export class BBox {
9192
this.w = def.w || 0;
9293
this.h = ('h' in def ? def.h : -BIGDIMEN);
9394
this.d = ('d' in def ? def.d : -BIGDIMEN);
94-
this.x = this.y = this.L = this.R = 0;
95+
this.x = this.y = this.L = this.R = this.ic = 0;
9596
this.scale = this.rscale = 1;
9697
this.pwidth = '';
9798
}

mathjax3-ts/output/chtml/Wrapper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
118118
//
119119
// These don't have Wrapper subclasses, so add their styles here
120120
//
121-
'mjx-mi': {display: 'inline-block'},
122121
'mjx-mn': {display: 'inline-block'},
123122
'mjx-mtext': {display: 'inline-block'},
124123
'mjx-merror': {

mathjax3-ts/output/chtml/Wrappers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import {CHTMLWrapper} from './Wrapper.js';
2525
import {CHTMLmath} from './Wrappers/math.js';
26+
import {CHTMLmi} from './Wrappers/mi.js';
2627
import {CHTMLmo} from './Wrappers/mo.js';
2728
import {CHTMLms} from './Wrappers/ms.js';
2829
import {CHTMLmspace} from './Wrappers/mspace.js';
@@ -44,6 +45,7 @@ export const CHTMLWrappers: {[kind: string]: typeof CHTMLWrapper} = {
4445
[CHTMLmath.kind]: CHTMLmath,
4546
[CHTMLmrow.kind]: CHTMLmrow,
4647
[CHTMLinferredMrow.kind]: CHTMLinferredMrow,
48+
[CHTMLmi.kind]: CHTMLmi,
4749
[CHTMLmo.kind]: CHTMLmo,
4850
[CHTMLms.kind]: CHTMLms,
4951
[CHTMLmspace.kind]: CHTMLmspace,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export class CHTMLTeXAtom extends CHTMLWrapper {
5656
*/
5757
public computeBBox(bbox: BBox) {
5858
super.computeBBox(bbox);
59+
if (this.childNodes[0] && this.childNodes[0].bbox.ic) {
60+
bbox.ic = this.childNodes[0].bbox.ic;
61+
}
5962
//
6063
// Center VCENTER atoms vertically
6164
//

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import {CHTMLWrapper} from '../Wrapper.js';
2525
import {BBox} from '../BBox.js';
2626
import {TextNode} from '../../../core/MmlTree/MmlNode.js';
27+
import {CharOptions} from '../FontData.js';
2728

2829
/*****************************************************************/
2930
/*
@@ -63,19 +64,31 @@ export class CHTMLTextNode extends CHTMLWrapper {
6364
// FIXME: measure this using DOM, if possible
6465
} else {
6566
const chars = this.unicodeChars((this.node as TextNode).getText());
66-
let [h, d, w] = this.font.getChar(variant, chars[0]) || [0, 0, 0];
67+
let [h, d, w, data] = this.getChar(variant, chars[0]);
6768
bbox.h = h;
6869
bbox.d = d;
6970
bbox.w = w;
71+
bbox.ic = data.ic || 0;
7072
for (let i = 1, m = chars.length; i < m; i++) {
71-
[h, d, w] = this.font.getChar(variant, chars[i]) || [0, 0, 0];
73+
[h, d, w, data] = this.getChar(variant, chars[i]);
7274
bbox.w += w;
7375
if (h > bbox.h) bbox.h = h;
7476
if (d > bbox.d) bbox.d = d;
77+
bbox.ic = data.ic || 0;
7578
}
7679
}
7780
}
7881

82+
/*
83+
* @param{string} variant The variant in which to look for the character
84+
* @param{number} n The number of the character to look up
85+
* @return{CharData} The full CharData object, with CharOptions guaranteed to be defined
86+
*/
87+
protected getChar(variant: string, n: number) {
88+
const char = this.font.getChar(variant, n) || [0, 0, 0, null];
89+
return [char[0], char[1], char[2], char[3] || {}] as [number, number, number, CharOptions];
90+
}
91+
7992
/******************************************************/
8093
/*
8194
* TextNodes don't need these, since these properties
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*************************************************************
2+
*
3+
* Copyright (c) 2017 The MathJax Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/**
19+
* @fileoverview Implements the CHTMLmi wrapper for the MmlMi object
20+
*
21+
* @author [email protected] (Davide Cervone)
22+
*/
23+
24+
import {CHTMLWrapper} from '../Wrapper.js';
25+
import {MmlMi} from '../../../core/MmlTree/MmlNodes/mi.js';
26+
import {BBox} from '../BBox.js';
27+
28+
/*****************************************************************/
29+
/*
30+
* The CHTMLmi wrapper for the MmlMi object
31+
*/
32+
export class CHTMLmi extends CHTMLWrapper {
33+
public static kind = MmlMi.prototype.kind;
34+
35+
/*
36+
* True if no italic correction should be used
37+
*/
38+
public noIC: boolean = false;
39+
40+
/*
41+
* @override
42+
*/
43+
public toCHTML(parent: HTMLElement) {
44+
super.toCHTML(parent);
45+
if (this.noIC) {
46+
this.chtml.setAttribute('noIC', 'true');
47+
}
48+
}
49+
50+
/*
51+
* @override
52+
*/
53+
public computeBBox(bbox: BBox) {
54+
super.computeBBox(bbox);
55+
const child = this.childNodes[this.childNodes.length-1];
56+
if (child && child.bbox.ic) {
57+
bbox.ic = child.bbox.ic;
58+
bbox.w += bbox.ic;
59+
}
60+
}
61+
62+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
import {CHTMLWrapper, StringMap} from '../Wrapper.js';
25+
import {CHTMLWrapperFactory} from '../WrapperFactory.js';
2526
import {MmlMo} from '../../../core/MmlTree/MmlNodes/mo.js';
2627
import {MmlNode} from '../../../core/MmlTree/MmlNode.js';
2728
import {BBox} from '../BBox.js';
@@ -104,12 +105,18 @@ export class CHTMLmo extends CHTMLWrapper {
104105

105106
};
106107

108+
/*
109+
* True if no italic correction should be used
110+
*/
111+
public noIC: boolean = false;
112+
107113
/*
108114
* The font size that a stretched operator uses.
109115
* If -1, then stretch arbitrarily, and bbox gives the actual height, depth, width
110116
*/
111117
public size: number = null;
112118

119+
113120
/*
114121
* @override
115122
*/
@@ -121,6 +128,9 @@ export class CHTMLmo extends CHTMLWrapper {
121128
this.getStretchedVariant([]);
122129
}
123130
let chtml = this.standardCHTMLnode(parent);
131+
if (this.noIC) {
132+
chtml.setAttribute('noIC', 'true');
133+
}
124134
if (this.stretch && this.size < 0) {
125135
this.stretchHTML(chtml, symmetric);
126136
} else {
@@ -196,6 +206,11 @@ export class CHTMLmo extends CHTMLWrapper {
196206
}
197207
if (this.stretch && this.size < 0) return;
198208
super.computeBBox(bbox);
209+
const child = this.childNodes[this.childNodes.length-1];
210+
if (child && child.bbox.ic) {
211+
bbox.ic = child.bbox.ic;
212+
if (!this.noIC) bbox.w += bbox.ic;
213+
}
199214
if (symmetric) {
200215
const d = ((bbox.h + bbox.d) / 2 + this.font.params.axis_height) - bbox.h;
201216
bbox.h += d;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export class CHTMLmsqrt extends CHTMLWrapper {
5353
},
5454
'mjx-sqrt > mjx-box': {
5555
'border-top': '.07em solid'
56+
},
57+
'mjx-sqrt.mjx-tall > mjx-box': {
58+
'padding-left': '.3em',
59+
'margin-left': '-.3em'
5660
}
5761
};
5862

@@ -126,7 +130,7 @@ export class CHTMLmsqrt extends CHTMLWrapper {
126130
* @override
127131
*/
128132
public toCHTML(parent: HTMLElement) {
129-
const surd = this.childNodes[this.surd];
133+
const surd = this.childNodes[this.surd] as CHTMLmo;
130134
const base = this.childNodes[this.base];
131135
//
132136
// Get the parameters for the spacing of the parts
@@ -153,6 +157,14 @@ export class CHTMLmsqrt extends CHTMLWrapper {
153157
this.addRoot(ROOT, root, sbox);
154158
surd.toCHTML(SURD);
155159
base.toCHTML(BASE);
160+
if (surd.size < 0) {
161+
//
162+
// size < 0 means surd is multi-character. The angle glyph at the
163+
// top is hard to align with the horizontal line, so overlap them
164+
// using CSS.
165+
//
166+
SQRT.classList.add('mjx-tall');
167+
}
156168
}
157169

158170
/*

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class CHTMLmsub extends CHTMLscriptbase {
5050
* @override
5151
*/
5252
protected getOffset(bbox: BBox, sbox: BBox) {
53-
return -this.getV(bbox, sbox);
53+
return [0, -this.getV(bbox, sbox)];
5454
}
5555

5656
}
@@ -63,6 +63,8 @@ export class CHTMLmsub extends CHTMLscriptbase {
6363
export class CHTMLmsup extends CHTMLscriptbase {
6464
public static kind = MmlMsup.prototype.kind;
6565

66+
public static useIC: boolean = true;
67+
6668
/*
6769
* @override
6870
*/
@@ -76,7 +78,8 @@ export class CHTMLmsup extends CHTMLscriptbase {
7678
* @override
7779
*/
7880
public getOffset(bbox: BBox, sbox: BBox) {
79-
return this.getU(bbox, sbox);
81+
const x = (this.baseCore.bbox.ic ? .2 * this.baseCore.bbox.ic + .05 : 0);
82+
return [x, this.getU(bbox, sbox)];
8083
}
8184

8285
}
@@ -99,6 +102,8 @@ export class CHTMLmsubsup extends CHTMLscriptbase {
99102
}
100103
};
101104

105+
public static noIC: boolean = true;
106+
102107
/*
103108
* Cached values for the script offsets and separation (so if they are
104109
* computed in computeBBox(), they don't have to be recomputed for toCHTML())
@@ -131,6 +136,10 @@ export class CHTMLmsubsup extends CHTMLscriptbase {
131136
this.supChild.toCHTML(stack);
132137
stack.appendChild(this.html('mjx-spacer', {style: {'margin-top': this.em(q)}}));
133138
this.subChild.toCHTML(stack);
139+
const corebox = this.baseCore.bbox;
140+
if (corebox.ic) {
141+
this.supChild.chtml.style.marginLeft = this.em((1.2 * corebox.ic + .05) / this.supChild.bbox.rscale);
142+
}
134143
}
135144

136145
/*
@@ -162,8 +171,21 @@ export class CHTMLmsubsup extends CHTMLscriptbase {
162171
if (this.UVQ) return this.UVQ;
163172
const tex = this.font.params;
164173
const t = 3 * tex.rule_thickness;
165-
let [u, v] = (this.isCharBase() ? [0, 0] : [this.getU(basebox, supbox),
166-
Math.max(basebox.d + tex.sub_drop * subbox.rscale, tex.sub2)]);
174+
const subscriptshift = this.length2em(this.node.attributes.get('subscriptshift'), tex.sub2);
175+
const drop = (this.isCharBase() ? 0 : basebox.d + tex.sub_drop * subbox.rscale);
176+
//
177+
// u and v are the veritcal shifts of the scripts, initially set to minimum values and then adjusted
178+
//
179+
let [u, v] = [this.getU(basebox, supbox), Math.max(drop, subscriptshift)];
180+
//
181+
// q is the space currently between the super- and subscripts.
182+
// If it is less than 3 rule thicknesses,
183+
// increase the subscript offset to make the space 3 rule thicknesses
184+
// If the bottom of the superscript is below 4/5 of the x-height
185+
// raise both the super- and subscripts by the difference
186+
// (make the bottom of the superscript be at 4/5 the x-height, and the
187+
// subscript 3 rule thickness below that).
188+
//
167189
let q = (u - supbox.d * supbox.rscale) - (subbox.h * subbox.rscale - v);
168190
if (q < t) {
169191
v += t - q;
@@ -173,6 +195,10 @@ export class CHTMLmsubsup extends CHTMLscriptbase {
173195
v -= p;
174196
}
175197
}
198+
//
199+
// Make sure the shifts are at least the minimum amounts and
200+
// return the shifts and the space between the scripts
201+
//
176202
u = Math.max(this.length2em(this.node.attributes.get('superscriptshift'), u), u);
177203
v = Math.max(this.length2em(this.node.attributes.get('subscriptshift'), v), v);
178204
q = (u - supbox.d * supbox.rscale) - (subbox.h * subbox.rscale - v);

0 commit comments

Comments
 (0)