Reputation: 11
I am trying to use MathJax in my iPhone app that I am building. I currently have both MathJax and the unpacked version of MathJax in my Resources folder. I have a html file in my Resources folder that is a direct copy of the sample.html file in the MathJax test folder. I then have a view that loads and when it does loads data into a UIWebView.
When the view loads it gets the data from the file like this:
NSString *htmlText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
The File path is retrieved by doing the following: `NSString *filePath = [[NSBundle mainBundle] pathForResource:"SSS" ofType:@"html"];
Then I have the MathJax folders in my resource folders and do have them setup so that they are listed under Copy Bundle Resources not Compile Sources in the Build Phases.
Once I have the htmlText in the string. I go to load the data in the UIWebView. I do this the following way:
[htmlView loadHTMLString:htmlText baseURL:[[NSBundle mainBundle] resourceURL]];
The webpage loads into the UIWebView but none of the LaTex is rendered correctly. When I load the sample.html page within the MathJax folder it loads correctly, so I know that I have that setup right. Any help would be great.
Thanks
Upvotes: 1
Views: 1033
Reputation: 11
Use:
NSString *basePath = [[NSBundle mainBundle]
pathForResource:@"htmlFileName" ofType:@"html"
inDirectory:@"."];
NSURL *baseURL = [NSURL fileURLWithPath:basePath];
[webview loadHTMLString:htmlString baseURL:baseURL];
This way relative paths will be used properly.
Upvotes: 1
Reputation: 116
I have added a new post about using MathJax v1.1a locally here. Davide have suggested some further improvements which I haven't got time to try yet, but the existing code should help with your problem, hope this helps.
Upvotes: 0