Question

I don't understand why this isn't working. I have a test.htm file sitting on my desktop that looks like this:

<html><head>

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full"></script></head>
<body>

This is $x^2$

</body></html>

and I have a WebView that is loading this from my desktop via

[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"file:///Users/john/Desktop/test.htm"]]];

which works fine. The page loads, the MathJax javascript runs, and that $x^2$ is turned into a nice typeset math script.

However, if I try to do this:

[[webView mainFrame] loadHTMLString:@"<html><head><script type=\"text/x-mathjax-config\">MathJax.Hub.Config({tex2jax: {inlineMath: [[\"$\",\"$\"],[\"\\\\(\",\"\\\\)\"]]}});</script><script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full\"></script></head><body>This is $x^2$</body></html>" baseURL:[NSURL URLWithString:@"file:///"]];

which loads exactly the same webpage after newlines are killed and \'s are replaced with "\" and "'s are replaced with '\"', the JavaScript fails to run, and I just see the plain text This is $x^2$ without the $x^2$ being rendered via MathJax.

Is there some secret, "no really webview, please execute javascript for me" command that I am missing?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top