manav patadia
manav patadia

Reputation: 81

MathJax to view mathMl in WebView of android

For those who want complete solution for MathMl in android: Advantages: Best in rendering Mathml in android webview Online MathJax doesn't require any space in your app Offline Mathjax is also very light weighted I will prefer online Mathjax as its just few lines code which will render any mathml into your WebView The code is in the answer part:

Upvotes: 2

Views: 3303

Answers (1)

manav patadia
manav patadia

Reputation: 81

wq = (WebView) findViewById(R.id.qtext);
        wq.getSettings().setJavaScriptEnabled(true);
        wq.getSettings().setLoadWithOverviewMode(true);
if (android.os.Build.VERSION.SDK_INT < 19)
        {
            wq.loadDataWithBaseURL("http://bar","<script type='text/javascript' "
                            +"src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS-MML_HTMLorMML'>"
                            +"</script><math display='block'>"+doubleEscapeTeX("Your Mathml code")+"</math>",
                    "text/html","utf-8","");
        }
        else
        {
            wq.loadDataWithBaseURL("http://bar","<script type='text/javascript' "
                            +"src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS-MML_HTMLorMML'>"
                            +"</script><math display='block'>"+doubleEscapeTeX("Your Mathml code")+"</math>",
                    "text/html","utf-8","");
        }

Offline is little bit buggy it sometimes render and sometimes it does not. Don't forget to add internet permissions in your app

Upvotes: 2

Related Questions