@@ -136,11 +136,16 @@ export function EnrichedMathItemMixin<N, T, D, B extends Constructor<AbstractMat
136136 currentSpeech = document . options . sre . speech ;
137137 }
138138 const math = new document . options . MathItem ( '' , MmlJax ) ;
139- math . math = this . serializeMml ( SRE . toEnriched ( toMathML ( this . root ) ) ) ;
140- math . display = this . display ;
141- math . compile ( document ) ;
142- this . root = math . root ;
143- this . inputData . originalMml = math . math ;
139+ try {
140+ const mml = this . inputData . originalMml = toMathML ( this . root ) ;
141+ math . math = this . serializeMml ( SRE . toEnriched ( mml ) ) ;
142+ math . display = this . display ;
143+ math . compile ( document ) ;
144+ this . root = math . root ;
145+ this . inputData . enrichedMml = math . math ;
146+ } catch ( err ) {
147+ document . options . enrichError ( document , this , err ) ;
148+ }
144149 }
145150 this . state ( STATE . ENRICHED ) ;
146151 }
@@ -213,6 +218,13 @@ export interface EnrichedMathDocument<N, T, D> extends AbstractMathDocument<N, T
213218 * @return {EnrichedMathDocument } The MathDocument (so calls can be chained)
214219 */
215220 attachSpeech ( ) : EnrichedMathDocument < N , T , D > ;
221+
222+ /**
223+ * @param {EnrichedMathDocument } doc The MathDocument for the error
224+ * @paarm {EnrichedMathItem} math The MathItem causing the error
225+ * @param {Error } err The error being processed
226+ */
227+ enrichError ( doc : EnrichedMathDocument < N , T , D > , math : EnrichedMathItem < N , T , D > , err : Error ) : void ;
216228}
217229
218230/**
@@ -240,6 +252,9 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
240252 public static OPTIONS : OptionList = {
241253 ...BaseDocument . OPTIONS ,
242254 enableEnrichment : true ,
255+ enrichError : ( doc : EnrichedMathDocument < N , T , D > ,
256+ math : EnrichedMathItem < N , T , D > ,
257+ err : Error ) => doc . enrichError ( doc , math , err ) ,
243258 renderActions : expandable ( {
244259 ...BaseDocument . OPTIONS . renderActions ,
245260 enrich : [ STATE . ENRICHED ] ,
@@ -305,6 +320,12 @@ export function EnrichedMathDocumentMixin<N, T, D, B extends MathDocumentConstru
305320 return this ;
306321 }
307322
323+ /**
324+ */
325+ public enrichError ( _doc : EnrichedMathDocument < N , T , D > , _math : EnrichedMathItem < N , T , D > , err : Error ) {
326+ console . warn ( 'Enrichment error:' , err ) ;
327+ }
328+
308329 /**
309330 * @override
310331 */
0 commit comments