@@ -98,23 +98,32 @@ function envUndefined(_parser: TexParser, env: string) {
9898function filterNonscript ( { data} : { data : ParseOptions } ) {
9999 for ( const mml of data . getList ( 'nonscript' ) ) {
100100 //
101- // If we are in script or script-script style
102- // remove the space (either mspace or mrow containing it)
103- // and remove it (and its contents) from the other lists.
104- // Otherwise, if it is an mrow (which we added),
105- // replace the mrow with its contents
106- // and remove it from its list
101+ // This is the list of mspace elements or mrow > mstyle > mspace
102+ // that followed \nonscript macros to be tested for removal.
107103 //
108104 if ( mml . attributes . get ( 'scriptlevel' ) > 0 ) {
105+ //
106+ // The mspace needs to be removed, since we are in a script style.
107+ // Remove it from the DOM and from the list of mspace elements.
108+ //
109109 const parent = mml . parent ;
110110 parent . childNodes . splice ( parent . childIndex ( mml ) , 1 ) ;
111111 data . removeFromList ( mml . kind , [ mml ] ) ;
112+ //
113+ // If it is an mrow > mstyle > mspace, then we have just
114+ // removed the mrow from its list, and must remove
115+ // the mstyle and mspace from their lists as well.
116+ //
112117 if ( mml . isKind ( 'mrow' ) ) {
113118 const mstyle = mml . childNodes [ 0 ] as MmlNode ;
114119 data . removeFromList ( 'mstyle' , [ mstyle ] ) ;
115120 data . removeFromList ( 'mspace' , mstyle . childNodes [ 0 ] . childNodes as MmlNode [ ] ) ;
116121 }
117122 } else if ( mml . isKind ( 'mrow' ) ) {
123+ //
124+ // This is an mrow > mstyle > mspace but we're not in a script
125+ // style, so remove the mrow that we had added in the NonscriptItem.
126+ //
118127 mml . parent . replaceChild ( mml . childNodes [ 0 ] , mml ) ;
119128 data . removeFromList ( 'mrow' , [ mml ] ) ;
120129 }
0 commit comments