@@ -37,28 +37,16 @@ export class CHTMLmfrac extends CHTMLWrapper {
3737 public static kind = MmlMfrac . prototype . kind ;
3838
3939 public static styles : StyleList = {
40- 'mjx-strut' : {
41- display : 'inline-block' ,
42- height : '1em' ,
43- width : 0 ,
44- 'vertical-align' : '-.25em'
45- } ,
46- 'mjx-hstrut' : {
40+ 'mjx-frac' : {
4741 display : 'inline-block' ,
48- height : '.75em' ,
49- width : 0
42+ 'vertical-align' : '0.17em' , // axis_height - 1.5 * rule_thickness
43+ padding : '0 .22em' // nulldelimiterspace + .1 (for line's -.1em margin)
5044 } ,
51- 'mjx-dstrut' : {
52- display : 'inline-block' ,
53- height : '.25em' ,
54- width : 0 ,
55- 'vertical-align' : '-.25em'
45+ 'mjx-frac[type="d"]' : {
46+ 'vertical-align' : '.04em' // axis_height - 3.5 * rule_thickness
5647 } ,
57-
58- 'mjx-frac' : {
59- display : 'inline-block' ,
60- 'vertical-align' : '0.145em' ,
61- padding : '0 .1em'
48+ 'mjx-frac[delims="true"]' : {
49+ padding : '0 .1em' // .1 (for line's -.1em margin)
6250 } ,
6351 'mjx-dtable' : {
6452 display : 'inline-table' ,
@@ -67,6 +55,10 @@ export class CHTMLmfrac extends CHTMLWrapper {
6755 'mjx-dtable > *' : {
6856 'font-size' : '2000%'
6957 } ,
58+ 'mjx-dbox' : {
59+ display : 'block' ,
60+ 'font-size' : '5%'
61+ } ,
7062 'mjx-row' : {
7163 display : 'table-row'
7264 } ,
@@ -78,40 +70,68 @@ export class CHTMLmfrac extends CHTMLWrapper {
7870 display : 'block' ,
7971 'text-align' : 'center'
8072 } ,
81- 'mjx-dbox' : {
82- display : 'block' ,
83- 'font-size' : '5%'
73+
74+ 'mjx-den[align="right"], mjx-num[align="right"]' : {
75+ align : 'right'
76+ } ,
77+ 'mjx-den[align="left"], mjx-num[align="left"]' : {
78+ align : 'left'
79+ } ,
80+
81+ 'mjx-nstrut' : {
82+ display : 'inline-block' ,
83+ height : '.054em' , // num2 - a - 1.5t
84+ width : 0 ,
85+ 'vertical-align' : '-.054em' // ditto
86+ } ,
87+ 'mjx-nstrut[type="d"]' : {
88+ height : '.217em' , // num1 - a - 3.5t
89+ 'vertical-align' : '-.217em' , // ditto
90+ } ,
91+ 'mjx-dstrut' : {
92+ display : 'inline-block' ,
93+ height : '.505em' , // denom2 + a - 1.5t
94+ width : 0
95+ } ,
96+ 'mjx-dstrut[type="d"]' : {
97+ height : '.726em' , // denom1 + a - 3.5t
8498 } ,
8599
86100 'mjx-line' : {
87101 display : 'block' ,
88102 'box-sizing' : 'border-box' ,
89103 'min-height' : '1px' ,
90- height : '.06em' ,
91- 'border-top' : '.06em solid' ,
92- margin : '.06em -.1em' ,
104+ height : '.06em' , // t = rule_thickness
105+ 'border-top' : '.06em solid' , // t
106+ margin : '.06em -.1em' , // t
93107 overflow : 'hidden'
108+ } ,
109+ 'mjx-line[type="d"]' : {
110+ margin : '.18em -.1em' // 3t
94111 }
112+
95113 } ;
96114
97115 /*
98116 * @override
99117 */
100118 public toCHTML ( parent : HTMLElement ) {
119+ this . chtml = this . standardCHTMLnode ( parent ) ;
120+ const attr = this . node . attributes . getList ( 'displaystyle' , 'scriptlevel' ) ;
121+ const style = ( attr . displaystyle && attr . scriptlevel === 0 ? { type : 'd' } : { } ) ;
122+ const fstyle = ( this . node . getProperty ( 'withDelims' ) ? { ...style , delims : 'true' } : style ) ;
101123 let num , den ;
102- let chtml = this . html ( 'mjx-frac' , { } , [
103- num = this . html ( 'mjx-num' , { } , [ this . html ( 'mjx-dstrut' ) ] ) ,
124+ this . chtml . appendChild ( this . html ( 'mjx-frac' , fstyle , [
125+ num = this . html ( 'mjx-num' , { } , [ this . html ( 'mjx-nstrut' , style ) ] ) ,
104126 this . html ( 'mjx-dbox' , { } , [
105127 this . html ( 'mjx-dtable' , { } , [
106- this . html ( 'mjx-line' ) ,
128+ this . html ( 'mjx-line' , style ) ,
107129 this . html ( 'mjx-row' , { } , [
108- den = this . html ( 'mjx-den' , { } , [ this . html ( 'mjx-hstrut' ) ] )
130+ den = this . html ( 'mjx-den' , { } , [ this . html ( 'mjx-dstrut' , style ) ] )
109131 ] )
110132 ] )
111133 ] )
112- ] ) ;
113- this . chtml = parent . appendChild ( chtml ) ;
114- this . handleScale ( ) ;
134+ ] ) ) ;
115135 this . childNodes [ 0 ] . toCHTML ( num ) ;
116136 this . childNodes [ 1 ] . toCHTML ( den ) ;
117137 }
@@ -121,14 +141,16 @@ export class CHTMLmfrac extends CHTMLWrapper {
121141 */
122142 public computeBBox ( bbox : BBox ) {
123143 bbox . empty ( ) ;
144+ const attr = this . node . attributes . getList ( 'displaystyle' , 'scriptlevel' ) ;
145+ const display = attr . displaystyle && attr . scriptlevel === 0 ;
124146 const nbox = this . childNodes [ 0 ] . getBBox ( ) ;
125147 const dbox = this . childNodes [ 1 ] . getBBox ( ) ;
126- const pad = ( this . node . getProperty ( 'withDelims' ) as boolean ? this . font . params . nulldelimiterspace : 0 ) ;
148+ const pad = ( this . node . getProperty ( 'withDelims' ) as boolean ? 0 : this . font . params . nulldelimiterspace ) ;
127149 const a = this . font . params . axis_height ;
128- const t = this . font . params . rule_thickness ;
129- bbox . combine ( nbox , pad , a + 1.5 * t + Math . max ( nbox . d , .25 ) ) ;
130- bbox . combine ( dbox , pad , a - 1.5 * t - Math . max ( dbox . h , .75 ) ) ;
131- bbox . w += pad + .2 ;
150+ const T = ( display ? 3.5 : 1.5 ) * this . font . params . rule_thickness ;
151+ bbox . combine ( nbox , 0 , a + T + Math . max ( nbox . d * nbox . rscale , display ? .217 : .054 ) ) ;
152+ bbox . combine ( dbox , 0 , a - T - Math . max ( dbox . h * dbox . rscale , display ? .726 : .505 ) ) ;
153+ bbox . w += 2 * pad + .2 ;
132154 bbox . clean ( ) ;
133155 }
134156
0 commit comments