0

I have finally gotten jqMath to work in Android Studio, but then I realize that it does not format the \text and \table correctly! https://mathscribe.com/author/jqmath.html At the jqMath homepage above, the examples show how to use \text and \table.

In my project I use this string.

$$\text"Molarity" = \text"moles of solute" / \text"liters of solution"$$

And this code for jqMath.

WebView webView = new WebView(context);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
String path="file:///android_asset/";
String js = "<html><head>"
            + "<link rel='stylesheet' href='"+path+"jqmath-0.4.3.css'>"
            + "<script src='"+path+"jquery-1.4.3.min.js'></script>"
            + "<script src='"+path+"jqmath-etc-0.4.6.min.js'></script>"
            + "</head><body>"
            + "<script>var s = '"+formulaText+"';jqMath.parseMath(s);document.write(s);</script></body>";
webView.loadDataWithBaseURL( "file:///android_asset/", js, "text/html", "utf-8", null );

And this is the result.

here

When I entered the same thing in on the homepage it displayed this.

Please help - I have no idea why the formula formatting is working, but \text and \table and all the \ command isn't formatting right!?!?

Community
  • 1
  • 1
Iyatsu
  • 37
  • 1
  • 1
  • 7

1 Answers1

0

Ok so, I ended up finding the answer myself. The problem wasn't with the jqMath! It was with Android Studio! Android Studio has this weird way of parsing backslashes \ so I had to change the text from

$$\text"Molarity" = \text"moles of solute" / \text"liters of solution"$$

to

$\\\\text\\\"Molarity\\\" = \\\\text\\\"moles of solute\\\" / \\\\text\\\"liters of solution\\\"$

This is because strings in Android Studio seem to undergo automatic backslash parsing. So my previous text was getting changed before undergoing jqMath format. By adding more backlashes (four backslashes for every backslash) I can turn the string into the right string to go through jqMath!

Iyatsu
  • 37
  • 1
  • 1
  • 7