Search code examples
androidwebviewmathjax

Android MathJax in Webview using loadDataWithBaseUrl


Thank you for considering this post.I have a html file of containing lot of math formulas in single page, as shown below

<p id="p006_002"><span class="class_a">a</span>&#x00A0;&#x00A0;<math><mrow><mn>7</mn><mi>x</mi><mo>&#x2212;</mo><mn>4</mn><mo>=</mo><mn>17</mn></mrow></math></p> <p id="p007_002"><span class="blue-no">b</span>&#x00A0;&#x00A0;

<math display='inline'><mrow><mfrac><mrow><mn>3</mn><mi>x</mi><mo>&#x2212;</mo><mn>2</mn></mrow><mn>4</mn></mfrac><mo>+</mo><mn>5</mn><mo>=</mo><mn>1</mn></mrow></math></p>

<math display='inline'><mrow><mn>2</mn><mrow><mo>(</mo><mrow><mfrac><mrow><mn>4</mn><mi>x</mi></mrow><mn>5</mn></mfrac><mo>&#x2212;</mo><mn>1</mn></mrow><mo>)</mo></mrow><mo>=</mo><mn>6</mn></mrow></math> </p>

The Mathjax link is provided as

<script type="text/javascript" src="mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

In Android Android 4.2.2 , When i use WebView.loadUrl("file"), MathJax get loaded , and formula getting generated, But When I use

WebView.loadDataWithBaseUrl("baseurl","file as string","text/html","utf-8");

Forumala fails to get rendered.I want these things to get work from Android 4.0.3.Please Help me to Solve this issue.Thank you


Solution

  • I found out a solution. But updating it so late. It may help others to solve this problem, if they are facing it in future. For loading Inline mathjax with webview's loadDataWithBaseUrl .I have replaced all the file(css,js) etc references as complete path(example: "file:///),and I loaded html as

    Webview.loadDataBaseWithUrl("http://bar","file:///<file path>","text/html","utf-8);
    

    It is necessary to call mathJax on page finish.