Search code examples
javaandroid-studiojqmath

Correct. escape sequence for over bar?


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.


Solution

  • 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.