@@ -26,7 +26,7 @@ import {CHTMLWrapperFactory} from '../WrapperFactory.js';
2626import { CHTMLmo } from './mo.js' ;
2727import { BBox } from '../BBox.js' ;
2828import { MmlMsqrt } from '../../../core/MmlTree/MmlNodes/msqrt.js' ;
29- import { MmlNode , AbstractMmlNode , TextNode } from '../../../core/MmlTree/MmlNode.js' ;
29+ import { MmlNode , AbstractMmlNode , TextNode , AttributeList } from '../../../core/MmlTree/MmlNode.js' ;
3030import { StyleList } from '../CssStyles.js' ;
3131import { DIRECTION } from '../FontData.js' ;
3232
@@ -40,11 +40,19 @@ export class CHTMLmsqrt extends CHTMLWrapper {
4040
4141 public static styles : StyleList = {
4242 'mjx-root' : {
43- display : 'inline-block'
43+ display : 'inline-block' ,
44+ 'white-space' : 'nowrap'
4445 } ,
4546 'mjx-surd' : {
4647 display : 'inline-block' ,
4748 'vertical-align' : 'top'
49+ } ,
50+ 'mjx-sqrt' : {
51+ display : 'inline-block' ,
52+ 'padding-top' : '.07em'
53+ } ,
54+ 'mjx-sqrt > mjx-box' : {
55+ 'border-top' : '.07em solid'
4856 }
4957 } ;
5058
@@ -87,19 +95,28 @@ export class CHTMLmsqrt extends CHTMLWrapper {
8795 const t = this . font . params . rule_thickness ;
8896 const p = ( this . node . attributes . get ( 'displaystyle' ) ? this . font . params . x_height : t ) ;
8997 this . surdH = h + d + 2 * t + p / 4 ;
90- surd . getStretchedVariant ( [ this . surdH , 0 ] ) ;
98+ surd . getStretchedVariant ( [ this . surdH - d , d ] , true ) ;
9199 }
92100
93101 /*
94- * Create an mo wrapper with the given text;
102+ * Create an mo wrapper with the given text,
103+ * link it in, and give it the right defaults.
95104 *
96105 * @param {string } text The text for the wrapped element
97106 * @return {CHTMLWrapper } The wrapped MmlMo node
98107 */
99108 protected createMo ( text : string ) {
100109 const mmlFactory = ( this . node as AbstractMmlNode ) . factory ;
101110 const textNode = ( mmlFactory . create ( 'text' ) as TextNode ) . setText ( text ) ;
102- const node = this . wrap ( mmlFactory . create ( 'mo' , { stretchy : true } , [ textNode ] ) ) as CHTMLmo ;
111+ const mml = mmlFactory . create ( 'mo' , { stretchy : true } , [ textNode ] ) ;
112+ const attributes = this . node . attributes ;
113+ const display = attributes . get ( 'display' ) as boolean ;
114+ const scriptlevel = attributes . get ( 'scriptlevel' ) as number ;
115+ const defaults : AttributeList = {
116+ mathsize : [ 'math' , attributes . get ( 'mathsize' ) ]
117+ } ;
118+ mml . setInheritedAttributes ( defaults , display , scriptlevel , false ) ;
119+ const node = this . wrap ( mml ) as CHTMLmo ;
103120 node . parent = this ;
104121 this . childNodes . push ( node ) ;
105122 return node ;
@@ -117,9 +134,6 @@ export class CHTMLmsqrt extends CHTMLWrapper {
117134 const sbox = surd . getBBox ( ) ;
118135 const bbox = base . getBBox ( ) ;
119136 const [ p , q ] = this . getPQ ( sbox ) ;
120- const [ x ] = this . getRootDimens ( sbox ) ;
121- const t = this . font . params . rule_thickness ;
122- const T = this . font . params . surd_height ;
123137 //
124138 // Create the HTML structure for the root
125139 //
@@ -129,14 +143,9 @@ export class CHTMLmsqrt extends CHTMLWrapper {
129143 ROOT = CHTML . appendChild ( this . html ( 'mjx-root' ) ) ;
130144 root = this . childNodes [ this . root ] ;
131145 }
132- const SQRT = CHTML . appendChild ( this . html ( 'mjx-box' , {
133- style : { paddingTop : this . px ( 2 * t - T , 1 ) }
134- } , [
146+ const SQRT = CHTML . appendChild ( this . html ( 'mjx-sqrt' , { } , [
135147 SURD = this . html ( 'mjx-surd' ) ,
136- BASE = this . html ( 'mjx-box' , { style : {
137- paddingTop : this . px ( q , 1 ) ,
138- borderTop : this . px ( T * bbox . scale , 1 ) + ' solid'
139- } } )
148+ BASE = this . html ( 'mjx-box' , { style : { paddingTop : this . em ( q ) } } )
140149 ] ) ) ;
141150 //
142151 // Add the child content
@@ -160,14 +169,14 @@ export class CHTMLmsqrt extends CHTMLWrapper {
160169 * @override
161170 */
162171 public computeBBox ( ) {
163- const BBOX = BBox . empty ( ) ;
172+ const BBOX = this . bbox . empty ( ) ;
164173 const sbox = this . childNodes [ this . surd ] . getBBox ( ) ;
165174 const bbox = new BBox ( this . childNodes [ this . base ] . getBBox ( ) ) ;
166175 const [ p , q ] = this . getPQ ( sbox ) ;
167176 const [ x ] = this . getRootDimens ( sbox ) ;
168177 const t = this . font . params . rule_thickness ;
169178 const H = bbox . h + q + t ;
170- bbox . h += q + 2 * t ; // FIXME: should take into accound minimums for this.px() used above
179+ bbox . h = H + t ;
171180 this . combineRootBBox ( BBOX , sbox ) ;
172181 BBOX . combine ( sbox , x , H - sbox . h ) ;
173182 BBOX . combine ( bbox , x + sbox . w , 0 ) ;
@@ -185,7 +194,7 @@ export class CHTMLmsqrt extends CHTMLWrapper {
185194 }
186195
187196 /*
188- * @param {BBox } sbox The bounding box for the surd character
197+ * @param {BBox } sbox The bounding box for the surd character
189198 * @return {number[] } The p, q, and x values for the TeX layout computations
190199 */
191200 protected getPQ ( sbox : BBox ) {
0 commit comments