I'm trying to implement partial rendering in my Markdown editor by converting Markdown/Tex in modified paragraphs only.
So basically, I have a #preview element that contains multiple .preview_section elements containing themselves the converted HTML paragraphs. When I update one or more .preview_section element, I'd like MathJax to process only those elements.
I tried different approaches:
- Pass the list of modified
.preview_sectionelements as typset parameter. That's the worst solution in term of performance. When passing more than 1 element, the time to render is almost multiplied by the number of elements. - Pass the
#previewelement as typeset parameter. The problem with this solution is that MathJax renders again the already renderedscript[type="math/tex; mode=display"]. I tried to set the tex2jaxignoreClass: "tex2jax_ignore"configuration and to add.tex2jax_ignoreto both unmodified.preview_sectionelements and already renderedscriptelements but it has no effect as it's not processed by tex2jax preprocessor (I suppose). - Pass the
#previewelement as typeset parameter but after removing all thescript[type="math/tex; mode=display"]from the preview. That's the most efficient, but I don't really like to remove these scripts from the preview.
Is there any ways to tell MathJax not to processing those script elements? Or any ideas before I plunge myself into the source code... Thanks.
Ok, I just found my problem. MathJax stores a JavaScript object in every
script[type="math/tex"]element in the DOM. This object, actually stored inelement.MathJax, contains :where
stateis the state of the preview (2 means PROCESSED). So the TypeSet does not render the preview again if it has already been rendered, unless you rewrite the script tag in the DOM (that's what I was doing), this case you lose the MathJax object and the state of the preview. That's why MathJax was keeping re-rendering all my scripts.