【发布时间】:2016-08-09 16:49:01
【问题描述】:
我有一组存储在 SQLite 数据库中的问题。对于数学科目,这些以 html 格式存储为公式/方程式。我检索问题并将其存储为字符串:
NSString *htmlstring = @"If 3<em>x</em><sup><strong>2</strong></sup> + 11<em>x</em> + 6 $$\\ge$$ 0, then <em>x</em> $$\\in $$";
为了在 UILabel 中显示这个字符串,我使用以下代码:
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
questionLbl.attributedText = attrStr;
此代码未按预期工作,输出为:
预期的输出是:
在从数据库中获取数据或将 html 转换为纯文本时,我不明白哪里出了问题。
更新
从下面 Ashmi 的回答中,我发现文本是乳胶格式。 我们如何将乳胶命令转换为符号现在是一个问题。有3种可能:
- 将 Latex 转换为 HTML(按照 Ashmi 的建议),然后加载该 HTML 在标签中。
- 将 Latex 转换为 unicode 字符以直接加载到标签中。
- 如果有的话,使用库,可能类似于 Math.h
【问题讨论】:
标签: ios objective-c sqlite nsattributedstring mathematical-expressions