Use MathJax more efficiently
From vivliostyle/vivliostyle.js#66 by @pkra:
From a quick look it seems like MathJax is used very inefficiently, i.e., vivliostyle is queuing equations individually instead of in batches; this prevents most of the performance optimizations built into MathJax.
Let me know if we can help with anything.
Thank you! I will read MathJax documents and ask you questions if needed.
By default, MathJax typesets the entire document at load time. Later, if you pass MathJax a DOM element, it will typeset all math in it. I'm guessing typesetting the underlying document first would be best but then you'd have to wait with any pagination work. If you first paginate, then MathJax will masssively change your pages and you'll have to re-paginate
Like most pagination tools you'll probably run into trouble with the HTML-based outputs as you might suddenly break in the middle of an equation; many prefer MathJax's SVG output for print because of this but the HTML output is usually nicer if you can make it work.
Note: I have no clue how vivliostyle does its magic, I'm just guessing from conversations with other pagination tools. It might very well be that there is no better way than your current approach. I would add that trying vivilostyle on a simple html page with math did not give good results but I know it's in an early phase and math is probably not a priority.
I'm guessing typesetting the underlying document first would be best but then you'd have to wait with any pagination work. If you first paginate, then MathJax will masssively change your pages and you'll have to re-paginate
That's right. The current implementation of Vivliostyle.js waits for each math to complete typesetting and then use the layout information to do pagination. I guess waiting for typesetting of all math in the whole document would delay the start of pagination, which is not desirable. Nevertheless it might be possible to process a chunk of maths in batch for performance gain. For example, one could collect maths which roughly fit in a single page and process them before the pagination.
HTML vs SVG output
I will try both and see if it goes well.
I would add that trying vivilostyle on a simple html page with math did not give good results but I know it's in an early phase and math is probably not a priority.
Math is not our highest priority for now, but bug reports and test cases are always welcome! :smile: