I have set of questions stored in SQLite database. For mathematics subject those are stored as formula/equations in html format. I retrieve question and stored it as string:
NSString *htmlstring = @"If 3<em>x</em><sup><strong>2</strong></sup> + 11<em>x</em> + 6 $$\\ge$$ 0, then <em>x</em> $$\\in $$";
To display this string in UILabel, I use following piece of code :
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
questionLbl.attributedText = attrStr;
This code not worked as expected and output is:
The expected output is:
I didn't understand where its going wrong, while fetching data from database or converting html to plain text.
UPDATE
From Ashmi's answer below I figured out the text is in Latex format. How can we convert latex command to symbol is now a question. There are 3 possibilities:
- Convert Latex to HTML(as suggested by Ashmi), then load that HTML in label.
- Convert Latex to unicode character to load directly in label.
- Using library if any, may be like Math.h