I am using following MathJax app code. http://cs.jsu.edu/wordpress/?p=498#comment-217
In following function i am trying to load file from asset directory.
You have to replace all the lines loadUrl(...)
with evaluateJavascript(...)
. But this is only for KitKat (API 19 or above), so you need to do an SDK version check first:
if (android.os.Build.VERSION.SDK_INT < 19) {
mWebView.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);");
} else {
mWebView.evaluateJavascript("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);",null);
}
if (android.os.Build.VERSION.SDK_INT < 19) {
v.loadUrl(url);
} else {
v.evaluateJavascript(url,null);
}
It looks like the MathJax
variable won't be set until you load the <script>
tag. You should move this into an onload listener. Something like:
<script type='text/x-mathjax-config'>
function setupMathJax() {
MathJax.Hub.Config(...);
}
</script>
<script type='text/javascript' src='file:///android_asset/MathJax/MathJax.js'></script>
<body onload='setupMathJax()'>
<span id='math'></span>
</body>
Perhaps the first <script>
containing your function setupMathJax()
is getting executed before your second <script>
has loaded your MathJax
file, causing the exception where MathJax is not defnied
. Try reversing the order of those tags.