@@ -32,6 +32,8 @@ import * as bitem from './BaseItems.js';
3232import { AbstractTags } from '../Tags.js' ;
3333import './BaseMappings.js' ;
3434import { getRange } from '../../../core/MmlTree/OperatorDictionary.js' ;
35+ import { MmlNode } from '../../../core/MmlTree/MmlNode.js' ;
36+ import ParseOptions from '../ParseOptions.js' ;
3537
3638/**
3739 * Remapping some ASCII characters to their Unicode operator equivalent.
@@ -89,6 +91,36 @@ function envUndefined(_parser: TexParser, env: string) {
8991 throw new TexError ( 'UnknownEnv' , 'Unknown environment \'%1\'' , env ) ;
9092}
9193
94+ /**
95+ * Filter for removing spacing following \nonscript
96+ * @param {ParseOptions } data The active tex parser.
97+ */
98+ function filterNonscript ( { data} : { data : ParseOptions } ) {
99+ for ( const mml of data . getList ( 'nonscript' ) ) {
100+ //
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
107+ //
108+ if ( mml . attributes . get ( 'scriptlevel' ) > 0 ) {
109+ const parent = mml . parent ;
110+ parent . childNodes . splice ( parent . childIndex ( mml ) , 1 ) ;
111+ data . removeFromList ( mml . kind , [ mml ] ) ;
112+ if ( mml . isKind ( 'mrow' ) ) {
113+ const mstyle = mml . childNodes [ 0 ] as MmlNode ;
114+ data . removeFromList ( 'mstyle' , [ mstyle ] ) ;
115+ data . removeFromList ( 'mspace' , mstyle . childNodes [ 0 ] . childNodes as MmlNode [ ] ) ;
116+ }
117+ } else if ( mml . isKind ( 'mrow' ) ) {
118+ mml . parent . replaceChild ( mml . childNodes [ 0 ] , mml ) ;
119+ data . removeFromList ( 'mrow' , [ mml ] ) ;
120+ }
121+ }
122+ }
123+
92124
93125/**
94126 * @constructor
@@ -135,19 +167,21 @@ export const BaseConfiguration: Configuration = Configuration.create(
135167 [ bitem . MmlItem . prototype . kind ] : bitem . MmlItem ,
136168 [ bitem . FnItem . prototype . kind ] : bitem . FnItem ,
137169 [ bitem . NotItem . prototype . kind ] : bitem . NotItem ,
170+ [ bitem . NonscriptItem . prototype . kind ] : bitem . NonscriptItem ,
138171 [ bitem . DotsItem . prototype . kind ] : bitem . DotsItem ,
139172 [ bitem . ArrayItem . prototype . kind ] : bitem . ArrayItem ,
140173 [ bitem . EqnArrayItem . prototype . kind ] : bitem . EqnArrayItem ,
141174 [ bitem . EquationItem . prototype . kind ] : bitem . EquationItem
142- } ,
143- options : {
144- maxMacros : 1000 ,
145- baseURL : ( typeof ( document ) === 'undefined' ||
146- document . getElementsByTagName ( 'base' ) . length === 0 ) ?
147- '' : String ( document . location ) . replace ( / # .* $ / , '' )
148- } ,
149- tags : {
150- base : BaseTags
151- }
175+ } ,
176+ options : {
177+ maxMacros : 1000 ,
178+ baseURL : ( typeof ( document ) === 'undefined' ||
179+ document . getElementsByTagName ( 'base' ) . length === 0 ) ?
180+ '' : String ( document . location ) . replace ( / # .* $ / , '' )
181+ } ,
182+ tags : {
183+ base : BaseTags
184+ } ,
185+ postprocessors : [ [ filterNonscript , - 4 ] ]
152186 }
153187) ;
0 commit comments