0

I am using a string as my source for an equation, and whenever I try to add something like an overbar tag which is:

\ov5\ - creates a bar over the 5

However, when I add this into a Java string, for it to compile I am required to write it like this:

string x= "\\ov5\\";

It would appear that this way breaks JQMath and doesn't work, resulting in a broken equation. Here is the code in case I did something terribly wrong:

WebView webView;
String functext = "$$\\ov55\\$$";
    js = "<html><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></html>";
    webView.loadDataWithBaseURL("", js, "text/html", "UTF-8", "");

EDIT: For clarification, the end result oddly reads "$$\ov55$$".

Please note that when I try the same string on JQMath's website page here, it works as intended.

EDIT2: Here are some debug values for a breakpoint placed at webView.loadDataWithBaseURL:

actual string: String functext = "$$\\\\ov55\\\\$$";

actual displayed result: $$\ov55\$$

debug results:
functext = $$\\ov55\\$$
js = <html><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>$$\\ov55\\$$</body></html>

Any help with loading it in another way other than a string would help greatly.

daedsidog
  • 1,732
  • 2
  • 17
  • 36

2 Answers2

1

I think you want this:

String functext = "$$\\ov55\\$$";

(The first \ needs to be before the ov operator.)

EDIT: Another possibility (since the above was evidently just a typo in your post, not in your code) is that somewhere in the pipeline the string is being interpolated a second time. In that case, you would need to double-escape the backslashes:

String functext = "$$\\\\ov55\\\\$$";

P.S. If the end result reads "$$\ov55$$" then the problem seems to be before jqmath sees anything. The code you posted definitely does not produce that result for me.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Sorry, it was a typo. The issue still stands though, as mentioned in the edit – daedsidog Dec 06 '15 at 21:51
  • @JohanZ. - In that case, I had another idea. See my edit. – Ted Hopp Dec 06 '15 at 21:56
  • Following your advice, I used double backslashes, the end result was similar to the first one: "$$\ov55\$$" - another backslash at the end of the equation. – daedsidog Dec 06 '15 at 21:58
  • @JohanZ. - At least now the equation seems to be in correct form for jqmath. Does it still have problems with it? – Ted Hopp Dec 06 '15 at 21:59
  • The "result" I posted is what the WebView shows after jqmath worked with the equation, if you click the link I put in my main post, you would find a box where you could put your own input and have an equation shown to you. Instead of an overbarred 55 that I aim for, the end result IS instead "$$\ov55\$$". Instead of a 55 with a bar over it. I suspect its something to do with how Java strings processes the jqmath text, as it works perfectly on the website, but not in the Android code – daedsidog Dec 06 '15 at 22:03
  • A reminder that ANYTHING involving the use of backslashes in the jqmath string breaks the string, not specifically \ov – daedsidog Dec 06 '15 at 22:14
  • @JohanZ. - Okay, so double-escaping isn't right. The key, i think, is figuring out why the second backslash is missing on the resulting HTML page. Just to clarify: that's the result if you log the value of `js` (or inspect it in the debugger) just before calling `loadDataWithBaseURL`? – Ted Hopp Dec 06 '15 at 22:18
  • @JohanZ. - Those debug results look like you still have double-escaping in place. As I said, that appears to have been a misguided suggestion on my part. Go back to the original assignment (`String functext = "$$\\ov55\\$$";`) and repeat the debugging exercise. – Ted Hopp Dec 07 '15 at 16:43
  • I just tried it again, writing the actual string instead of functext in the js link appears to work, making a string variable out of it does not – daedsidog Dec 07 '15 at 16:52
  • I have isolated the problem: it appears that the closing backslash for the overbar tag cannot be the last item on the string, causing it to break. Adding a space or a character after the string, ie "$$\\ov55\\a$$" fixes my problem. I'll choose you as the right answer since you've been great help, might want to update your answer in case anyone stumbles upon this same issue. Thank you! – daedsidog Dec 07 '15 at 16:57
  • @JohanZ. - That's interesting. I can't say that I understand exactly what's going on. What's your opinion: was this a Java problem, a JavaScript problem, or a jqmath problem? – Ted Hopp Dec 07 '15 at 17:02
  • I'm on the same boat. It would appear to be a java issue, since on their website, using my first string format would work (for you as well), must have been something with the backslash escapes – daedsidog Dec 07 '15 at 17:21
  • The trailing backslash(es) are unnecessary and are sometimes harmful. I'd omit them. – Dave Barton Dec 07 '15 at 19:11
  • @DaveBarton - Excellent suggestion. It's what I would have suggested if I was more familiar with jqmath. – Ted Hopp Dec 07 '15 at 19:22
  • They are necessary to break the overbar. I don't want it on the entire number, but in this example, you are correct. – daedsidog Dec 08 '15 at 08:09
1

Also jqMath accepts ` (backquote) in place of \ if that makes things easier. Finally, I'd put a space between the ov and the 5 to clarify that it's not a macro named ov5. (Plus see my comment above to remove the final \.)

Dave Barton
  • 1,429
  • 13
  • 12