Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand your problem correctly, it seems the issue is due to the MathJax library has not completed loading (from the <code>loadDataWithBaseURL()</code> call) when you call the additional <code>loadUrl()</code>s to display the formula. The simplest fix is to wait for the <code>onPageFinished()</code> callback to make the call.</p> <p>For example, the following code seems to work fine on mine:</p> <pre><code>/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final WebView w = (WebView) findViewById(R.id.webview); w.getSettings().setJavaScriptEnabled(true); w.getSettings().setBuiltInZoomControls(true); w.loadDataWithBaseURL("http://bar", "&lt;script type='text/x-mathjax-config'&gt;" + "MathJax.Hub.Config({ " + "showMathMenu: false, " + "jax: ['input/TeX','output/HTML-CSS'], " + "extensions: ['tex2jax.js'], " + "TeX: { extensions: ['AMSmath.js','AMSsymbols.js'," + "'noErrors.js','noUndefined.js'] } " + "});&lt;/script&gt;" + "&lt;script type='text/javascript' " + "src='file:///android_asset/MathJax/MathJax.js'" + "&gt;&lt;/script&gt;&lt;span id='math'&gt;&lt;/span&gt;", "text/html", "utf-8", ""); w.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (!url.startsWith("http://bar")) return; w.loadUrl("javascript:document.getElementById('math').innerHTML='\\\\[" + doubleEscapeTeX("sample string") + "\\\\]';"); w.loadUrl("javascript:MathJax.Hub.Queue(['Typeset',MathJax.Hub]);"); } }); } </code></pre> <p><strong>Update</strong>: To accommodate additional output in the WebView, I would suggest adding HTML elements to the initial <code>loadDataWithBaseURL()</code> call. So for the example above, instead of this line at the end:</p> <pre><code> + "&gt;&lt;/script&gt;&lt;span id='math'&gt;&lt;/span&gt;", "text/html", "utf-8", ""); </code></pre> <p>We can do something like the following:</p> <pre><code> + "&gt;&lt;/script&gt;&lt;span id='text'&gt;Formula:&lt;/span&gt;" + "&lt;span id='math'&gt;&lt;/span&gt;", "text/html", "utf-8", ""); </code></pre> <p>Additionally, if you need to update that part interactively afterward, you can use the same mechanism that we used for the "math" part, something like:</p> <pre><code> w.loadUrl("javascript:document.getElementById('text').innerHTML='" + newText + "';"); </code></pre> <p>You can also use other HTML elements (instead of the <code>&lt;span&gt;</code> that we use above) if you want to have specific styling/formatting.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload