Skip to content

Commit 83f5c77

Browse files
committed
Merge remote-tracking branch 'origin/munderover-support'
2 parents a928e3e + cd4337e commit 83f5c77

File tree

7 files changed

+123
-17
lines changed

7 files changed

+123
-17
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ export class MmlMath extends AbstractMmlLayoutNode {
8787
* @override
8888
*/
8989
protected setChildInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean) {
90+
if (this.attributes.get('mode') === 'display') {
91+
this.attributes.setInherited('display', 'block');
92+
}
9093
attributes = this.addInheritedAttributes(attributes, this.attributes.getAllAttributes());
9194
display = (!!this.attributes.get('displaystyle') ||
9295
(!this.attributes.get('displaystyle') && this.attributes.get('display') === 'block'));

mathjax3-ts/output/chtml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class CHTML extends AbstractOutputJax {
105105
this.math = math;
106106
this.nodes.document = html.document;
107107
math.root.setTeXclass(null);
108-
let node = this.html('mjx-chtml', {'class': 'MathJax_CHTML MJX-TEX'});
108+
let node = this.html('mjx-chtml', {'class': 'MathJax MJX-CHTML MJX-TEX'});
109109
const scale = math.metrics.scale * this.options.scale;
110110
if (scale !== 1) {
111111
node.style.fontSize = percent(scale);

mathjax3-ts/output/chtml/Wrapper.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
105105
'mjx-chtml [size="hg"]': {'font-size': '207%'},
106106
'mjx-chtml [size="HG"]': {'font-size': '249%'},
107107

108+
'mjx-chtml [width="full"]': {
109+
width: '100%'
110+
},
111+
108112
'mjx-box': {display: 'inline-block'},
109113
'mjx-block': {display: 'block'},
110114
'mjx-itable': {display: 'inline-table'},
@@ -123,15 +127,7 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
123127
'background-color': 'yellow'
124128
},
125129

126-
'mjx-mphantom': {visibility: 'hidden'},
127-
128-
'mjx-math': {
129-
//
130-
// There will be more here when the math wrapper is written
131-
//
132-
display: 'inline-block',
133-
'line-height': '0px'
134-
}
130+
'mjx-mphantom': {visibility: 'hidden'}
135131

136132
};
137133

@@ -521,7 +517,7 @@ export class CHTMLWrapper extends AbstractWrapper<MmlNode, CHTMLWrapper> {
521517
* @param{number} rscale The relatie scale to apply
522518
* @return{HTMLElement} The HTML node (for chaining)
523519
*/
524-
setScale(chtml: HTMLElement, rscale: number) {
520+
protected setScale(chtml: HTMLElement, rscale: number) {
525521
const scale = (Math.abs(rscale - 1) < .001 ? 1 : rscale);
526522
if (chtml && scale !== 1) {
527523
const size = this.percent(scale);

mathjax3-ts/output/chtml/Wrappers.ts

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

2424
import {CHTMLWrapper} from './Wrapper.js';
25+
import {CHTMLmath} from './Wrappers/math.js';
2526
import {CHTMLmo} from './Wrappers/mo.js';
2627
import {CHTMLms} from './Wrappers/ms.js';
2728
import {CHTMLmspace} from './Wrappers/mspace.js';
@@ -40,6 +41,7 @@ import {CHTMLTeXAtom} from './Wrappers/TeXAtom.js';
4041
import {CHTMLTextNode} from './Wrappers/TextNode.js';
4142

4243
export const CHTMLWrappers: {[kind: string]: typeof CHTMLWrapper} = {
44+
[CHTMLmath.kind]: CHTMLmath,
4345
[CHTMLmrow.kind]: CHTMLmrow,
4446
[CHTMLinferredMrow.kind]: CHTMLinferredMrow,
4547
[CHTMLmo.kind]: CHTMLmo,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 CHTMLmath wrapper for the MmlMath object
20+
*
21+
* @author [email protected] (Davide Cervone)
22+
*/
23+
24+
import {CHTMLWrapper} from '../Wrapper.js';
25+
import {CHTMLWrapperFactory} from '../WrapperFactory.js';
26+
import {MmlMath} from '../../../core/MmlTree/MmlNodes/math.js';
27+
import {MmlNode} from '../../../core/MmlTree/MmlNode.js';
28+
import {StyleList} from '../CssStyles.js';
29+
30+
/*****************************************************************/
31+
/*
32+
* The CHTMLmath wrapper for the MmlMath object
33+
*/
34+
35+
export class CHTMLmath extends CHTMLWrapper {
36+
public static kind = MmlMath.prototype.kind;
37+
38+
public static styles: StyleList = {
39+
'mjx-math': {
40+
'line-height': 0,
41+
'text-align': 'left',
42+
'text-indent': 0,
43+
'font-style': 'normal',
44+
'font-weight': 'normal',
45+
'font-size': '100%',
46+
'font-size-adjust': 'none',
47+
'letter-spacing': 'normal',
48+
'word-wrap': 'normal',
49+
'word-spacing': 'normal',
50+
'white-space': 'nowrap',
51+
'direction': 'ltr',
52+
'padding': '1px 0'
53+
},
54+
'mjx-chtml.MJX-DISPLAY': {
55+
display: 'block',
56+
'text-align': 'center',
57+
margin: '1em 0'
58+
},
59+
'mjx-chtml.MJX-DISPLAY mjx-math': {
60+
padding: 0
61+
}
62+
};
63+
64+
/*
65+
* @override
66+
*/
67+
public toCHTML(parent: HTMLElement) {
68+
super.toCHTML(parent);
69+
if (this.node.attributes.get('display') === 'block') {
70+
this.chtml.setAttribute('display', 'true');
71+
parent.classList.add('MJX-DISPLAY');
72+
}
73+
}
74+
75+
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,19 @@ export class CHTMLmrow extends CHTMLWrapper {
4949
* @override
5050
*/
5151
public toCHTML(parent: HTMLElement) {
52-
let chtml = parent;
52+
let chtml = this.chtml = parent;
5353
if (!this.node.isInferred) {
5454
chtml = this.standardCHTMLnode(parent);
5555
}
5656
let hasNegative = false;
5757
for (const child of this.childNodes) {
5858
child.toCHTML(chtml);
59-
if (child.bbox && child.bbox.w < 0) {
59+
if (child.bbox.w < 0) {
6060
hasNegative = true;
6161
}
62+
if (child.bbox.pwidth) {
63+
this.makeFullWidth();
64+
}
6265
}
6366
// FIXME: handle line breaks
6467
if (hasNegative) {
@@ -69,8 +72,14 @@ export class CHTMLmrow extends CHTMLWrapper {
6972
}
7073

7174
/*
72-
* @return{number} The number of stretchable child nodes
75+
* Handle the case where a child has a percentage width by
76+
* marking the parent as 100% width.
7377
*/
78+
protected makeFullWidth() {
79+
this.bbox.pwidth = '100%';
80+
this.chtml.setAttribute('width', 'full');
81+
}
82+
7483
/*
7584
* Handle vertical stretching of children to match height of
7685
* other nodes in the row.

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ export class CHTMLmtable extends CHTMLWrapper {
3939

4040
public static styles: StyleList = {
4141
'mjx-mtable': {
42-
'vertical-align': '.25em'
42+
'vertical-align': '.25em',
43+
'text-align': 'center'
4344
},
4445
'mjx-mtable > mjx-itable': {
45-
'vertical-align': 'middle'
46+
'vertical-align': 'middle',
47+
'text-align': 'left'
48+
},
49+
'mjx-mtable[width="%"] > mjx-itable': {
50+
width: '100%'
4651
}
4752
};
4853

@@ -102,6 +107,7 @@ export class CHTMLmtable extends CHTMLWrapper {
102107
this.handleRowSpacing(lines, fspacing[1] || '0');
103108
this.handleRowLines();
104109
this.handleFrame(frame);
110+
this.handleWidth();
105111
}
106112

107113
/******************************************************************/
@@ -147,7 +153,7 @@ export class CHTMLmtable extends CHTMLWrapper {
147153
* Pad any short rows with extra cells
148154
*/
149155
protected padRows() {
150-
for (const row of Array.from(this.chtml.childNodes)) {
156+
for (const row of Array.from((this.chtml.firstChild as HTMLElement).childNodes)) {
151157
while (row.childNodes.length < this.numCols) {
152158
row.appendChild(this.html('mjx-mtd'));
153159
}
@@ -326,6 +332,21 @@ export class CHTMLmtable extends CHTMLWrapper {
326332
}
327333
}
328334

335+
/*
336+
* Handle percentage widths and fixed widths
337+
*/
338+
protected handleWidth() {
339+
let w = this.node.attributes.get('width') as string;
340+
if (w === 'auto') return;
341+
if (w.match(/%$/)) {
342+
this.bbox.pwidth = w;
343+
this.chtml.setAttribute('width','%');
344+
} else {
345+
w = this.em(this.length2em(w));
346+
}
347+
this.chtml.style.width = w;
348+
}
349+
329350
/******************************************************************/
330351

331352
/*

0 commit comments

Comments
 (0)