@@ -101,26 +101,32 @@ if (!window.MathJax) {
101101 AM . symbols . splice ( i , 0 , { input : trigger , ...newTriggers [ trigger ] . symbols } ) ;
102102 }
103103
104- return MathJax . startup . defaultReady ( ) ;
104+ MathJax . startup . defaultReady ( ) ;
105+ MathJax . startup . document . constructor . ProcessBits . allocate ( 'findScripts' ) ;
105106 }
106107 } ,
107108 options : {
108109 renderActions : {
109110 findScript : [
110111 10 ,
111112 ( doc ) => {
112- for ( const node of document . querySelectorAll ( 'script[type^="math/tex"]' ) ) {
113- const math = new doc . options . MathItem (
114- node . textContent ,
115- doc . inputJax [ 0 ] ,
116- ! ! node . type . match ( / ; * m o d e = d i s p l a y / )
117- ) ;
118- const text = document . createTextNode ( '' ) ;
119- node . parentNode . replaceChild ( text , node ) ;
120- math . start = { node : text , delim : '' , n : 0 } ;
121- math . end = { node : text , delim : '' , n : 0 } ;
122- doc . math . push ( math ) ;
113+ if ( doc . processed . isSet ( 'findScripts' ) ) return ;
114+ const containers = doc . adaptor . getElements ( doc . options . elements || [ doc . document . body ] , doc ) ;
115+ for ( const container of containers ) {
116+ for ( const node of container . querySelectorAll ( 'script[type^="math/tex"]' ) ) {
117+ const math = new doc . options . MathItem (
118+ node . textContent ,
119+ doc . inputJax [ 0 ] ,
120+ ! ! node . type . match ( / ; * m o d e = d i s p l a y / )
121+ ) ;
122+ const text = document . createTextNode ( '' ) ;
123+ node . parentNode . replaceChild ( text , node ) ;
124+ math . start = { node : text , delim : '' , n : 0 } ;
125+ math . end = { node : text , delim : '' , n : 0 } ;
126+ doc . math . push ( math ) ;
127+ }
123128 }
129+ doc . processed . set ( 'findScripts' ) ;
124130 } ,
125131 ''
126132 ]
0 commit comments