Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize performance on multiple typeset #524

Closed
benweet opened this issue Jul 26, 2013 · 5 comments
Closed

Optimize performance on multiple typeset #524

benweet opened this issue Jul 26, 2013 · 5 comments

Comments

@benweet
Copy link

benweet commented Jul 26, 2013

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_section elements 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 #preview element as typeset parameter. The problem with this solution is that MathJax renders again the already rendered script[type="math/tex; mode=display"]. I tried to set the tex2jax ignoreClass: "tex2jax_ignore" configuration and to add .tex2jax_ignore to both unmodified .preview_section elements and already rendered script elements but it has no effect as it's not processed by tex2jax preprocessor (I suppose).
  • Pass the #preview element as typeset parameter but after removing all the script[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.

@pkra
Copy link
Contributor

pkra commented Jul 26, 2013

Thanks, @benweet for posting here as well.

The texignore only works if you don't directly inject TeX in script tags. But as I wrote on the gist, MathJax shouldn't typeset everything in your preview so I'm wondering if something goes wrong in your preview that disconnects MathJax from its output. Can you link to a live version that we can look at?

@benweet
Copy link
Author

benweet commented Jul 26, 2013

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 in element.MathJax, contains :

checked: 1
elementJax: Object
preview: span.MathJax_Preview
startNumber: 0
state: 2

where state is 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.

Thank you for your help, it was actually a good idea to try to reproduce the problem in a test page. And MathJax is quiet easy to debug...

@benweet benweet closed this as completed Jul 26, 2013
@pkra
Copy link
Contributor

pkra commented Jul 27, 2013

Thanks for the update, @benweet -- I'm glad this worked out.

And MathJax is quite easy to debug...

That makes us very happy! (well, unless you meant the ellipsis ironically :( )

@benweet
Copy link
Author

benweet commented Jul 27, 2013

No I mean it. It took me an hour to set up the test page and 10 min to find the function prepareScripts in MathJax!

@pkra
Copy link
Contributor

pkra commented Jul 27, 2013

Awesome! Thanks for clarifying 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants