I've a web page that renders latex equations using mathjax. In order to load the equations faster, i'm trying to avoid the preprocessing step, by replacing the
math delimiters by <span class="MathJax_Preview">[loading...]</span><script type="math/tex;"> latex equation here </script>
But the problem is; while rendering, the html entities that comes within the equation are shown as such and hence the equations are not rendered properly.For eg, '&' is used for alignment of multiple steps. But it is displayed as &
Replacing the math delimiters by <script>
tag is done dynamically. If i remove this step, then the said issue is not there and html entities within equation are rendered properly.
How can i solve this?
My ultimate objective is to make the equation load faster. Show a preloder like [loading...] until the maths is typeset fully.
Thanks,
LS Developer
Note that the contents of the <script type="math/tex">
is TeX (or LaTeX), not HTML, and so HTML entities should not be included there. The contents of any <script>
in HTML is CDATA, and so no processing, including conversion of entities, is performed within it.
If you are using numeric entities like A
or A
then it is easy to replace those by the characters they represent. If you are using named entities, then you will need to translate them into their characters via a table lookup or other process. Better yet would be not to put in entities in the first place. Can you not perform that step? (I'm assuming that is done outside of your control.)
Note that the preprocessing step in MathJax is actually quite fast, and is not likely to be a bottleneck unless you have an enormous number of equations. It is the conversion to HTML that is the time sink. If you aren't using one of the combined configuration files, you will probably get a better improvement simply by moving to one of those than by removing the preprocessor step. If you already are using a combined configuration file, but aren't using the "-full" version, then moving to that will also speed up the processing of the math (since you won't have to wait for the input and output jax to load when they are first used).