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?
Ok, I "solved" this. For some reason the web view doesn't like my baseURL being file:///. When I set it to http://www.google.com, everything works fine. I don't understand what is wrong with passing it file:///. Additionally using
[[NSBundle mainBundle] URLForResource:@"blank" withExtension:@"htm"]
did not work, but that may be because there is no blank.htm in the bundle.