@@ -702,6 +702,13 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
702702 'mjx-container[data-mjx-clone-container]' : {
703703 padding : '2px ! important' ,
704704 } ,
705+ 'mjx-math > mjx-mlabeledtr' : {
706+ display : 'inline-block' ,
707+ 'margin-right' : '.5em ! important' ,
708+ } ,
709+ 'mjx-math > mjx-mtd' : {
710+ float : 'right' ,
711+ }
705712 } ) ;
706713
707714 /**
@@ -801,6 +808,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
801808 }
802809 mjx = container . cloneNode ( false ) . appendChild ( mjx ) . parentElement ;
803810 mjx . style . margin = '0' ;
811+ mjx . style . minWidth = '' ;
804812 }
805813 mjx . setAttribute ( 'data-mjx-clone-container' , 'true' ) ;
806814 return mjx ;
@@ -818,7 +826,10 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
818826 ) {
819827 for ( const child of enclosed ) {
820828 if ( child !== node ) {
821- mjx . appendChild ( child . cloneNode ( true ) ) ;
829+ const id = child . getAttribute ( 'data-semantic-id' ) ;
830+ if ( ! id || ! mjx . querySelector ( `[data-semantic-id="${ id } "]` ) ) {
831+ mjx . appendChild ( child . cloneNode ( true ) ) ;
832+ }
822833 }
823834 }
824835 }
@@ -856,9 +867,23 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
856867 x = X ;
857868 y = Y + bbox . y ;
858869 }
870+ //
871+ // Handle top-level expression with a tag
872+ //
873+ const g = container . querySelector ( 'g' ) ;
874+ if ( container . getAttribute ( 'width' ) === 'full' && g . firstChild . lastChild === node ) {
875+ mjx . innerHTML = '' ;
876+ mjx . appendChild ( container . cloneNode ( true ) . firstChild ) ;
877+ mjx . querySelector ( '.mjx-selected' ) . setAttribute ( 'data-mjx-clone' , 'true' ) ;
878+ mjx . querySelector ( '[data-sre-highlighter-added]' ) ?. remove ( ) ;
879+ return ;
880+ }
881+ //
882+ // All other expressions
883+ //
859884 ( mjx . firstChild as HTMLElement ) . setAttribute ( 'transform' , 'scale(1, -1)' ) ;
860- const W = parseFloat ( mjx . getAttribute ( 'viewBox' ) . split ( / / ) [ 2 ] ) ;
861- const w = parseFloat ( mjx . getAttribute ( 'width' ) ) ;
885+ const W = parseFloat ( ( mjx . getAttribute ( 'viewBox' ) || mjx . getAttribute ( 'data-mjx-viewBox' ) ) . split ( / / ) [ 2 ] ) ;
886+ const w = parseFloat ( mjx . style . minWidth || mjx . getAttribute ( 'width' ) ) ;
862887 mjx . setAttribute ( 'viewBox' , [ x , - ( y + height ) , width , height ] . join ( ' ' ) ) ;
863888 mjx . removeAttribute ( 'style' ) ;
864889 mjx . setAttribute ( 'width' , ( w / W ) * width + 'ex' ) ;
0 commit comments