I have to add MathJax functionality to my app.
According to some examples the correct script to be added is
<script type='text/x-mathjax-config'>"
+"MathJax.Hub.Config({ "
+ "showMathMenu: false, "
+ "jax: ['input/TeX','output/HTML-CSS'], "
+ "showProcessingMessages: false, "
+ "messageStyle: 'none', "
+ "extensions: ['tex2jax.js'], "
+ "TeX: { extensions: ['AMSmath.js','AMSsymbols.js',"
+ "'noErrors.js','noUndefined.js'] } "
+ "});</script>"
+ "<script type='text/javascript' "
+ "src='file:///android_asset/MathJax/es5/tex-mml-svg.js'"
+ "></script><span id='math'></span>
The script is loaded from local folder inside the Asset directory.
I have to add that script to a local HTML file when loaded in the Android WebView from another folder on the filesystem (private app folder).
The HTML page has math formulas inside that have to be read by the MathJax functions.
I cannot inject the script as a tag in the HTML file before loading. But also the rendering of the formulas have to be performed immediately after loading.
In the examples they suggest something like:
webView.loadDataWithBaseURL("http://bar", "<script type='text/x-mathjax-config'>"
+"MathJax.Hub.Config({ "
+ "showMathMenu: false, "
+ "jax: ['input/TeX','output/HTML-CSS'], "
+ "showProcessingMessages: false, "
+ "messageStyle: 'none', "
+ "extensions: ['tex2jax.js'], "
+ "TeX: { extensions: ['AMSmath.js','AMSsymbols.js',"
+ "'noErrors.js','noUndefined.js'] } "
+ "});</script>"
+ "<script type='text/javascript' "
+ "src='file:///android_asset/MathJax/es5/tex-mml-svg.js'"
+ "></script><span id='math'></span>","text/html","utf-8","");
That instruction is executed after the page is loaded, followed by
webView.evaluateJavascript("MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
that I think is the instruction to render all the math tags in the document
but I get
I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: MathJax is not defined"
What is the correct way to inject the script in the loaded page and perform the rendering?