1

I have a WebView that updates its jqMath equation every fraction of a second. Every now and then (more often when the equation's font is large) the equation displays the delimiting characters for a fraction of a second ($$,$,[\,(\). This usually happens on fast devices. Here is my code:

 String funcText = "4+5+6+8";
 js = "<div><head>" + "<link rel='stylesheet' " +
      "href='file:///android_asset/mathscribe/jqmath-0.4.3.css'>" + "<script>" +
      "src='file:///android_asset/mathscribe/jquery-1.4.3.min.js'></script>" + "<script" +
      " src='file:///android_asset/mathscribe/jqmath-etc-0.4.3.min.js'></script>" +
      "</head><body>" + "\\[" + funcText + "\\]</body></divl>";
 webView.loadDataWithBaseURL("", js, "text/html", "UTF-8", "");

jqMath will render this function correctly:

4+5+6+8

However, very rarely, it will display it with its delimiting blocks, for a fraction of a second:

[\4+5+6+8\]

Even though it only appears for a fraction of a second, it causes the text to jitter and look bugged.

I have no clue what could possibly cause this. Any help will be appreciated.

Will
  • 810
  • 6
  • 21
daedsidog
  • 1,732
  • 2
  • 17
  • 36

1 Answers1

1

jqMath calls M.parseMath(document.body) after the document is loaded, to convert jqMath strings to formatted mathematics. The conversion takes a small but nonzero amount of time. You can take steps to hide the webview or move parts of it offscreen if you want, for instance by temporarily setting a positioned element's css left property to -10000, but basically when most web pages are loaded, they take a little time before they look right. Reloading html every fraction of a second doesn't seem like a good idea in general. It'd be better to just change or reload the math when you need to, and as I say do the reformatting offscreen if you want ideal results. This is a common technique in any interactive page or app with nontrivial rendering or graphics.

If you want to call M.parseMath on part of a page yourself instead of reloading an entire webview, see Jqmath - apply after page load

Community
  • 1
  • 1
Dave Barton
  • 1,429
  • 13
  • 12
  • I have no experience working with JS or HTML, and frankly have used the code to configure the WebView from other questions. Can you tell me exactly how do I apply it after the page has loaded? – daedsidog Jan 26 '16 at 20:59
  • What I meant above was how to only reformat the math without having the reload the WebView! – daedsidog Jan 26 '16 at 21:16