Ios 将包含数学公式的Latex Comand的HTML文本转换为输出正确公式的纯文本或属性文本

Ios 将包含数学公式的Latex Comand的HTML文本转换为输出正确公式的纯文本或属性文本,ios,objective-c,sqlite,nsattributedstring,mathematical-expressions,Ios,Objective C,Sqlite,Nsattributedstring,Mathematical Expressions,我在SQLite数据库中存储了一组问题。对于数学科目,它们以html格式存储为公式/方程式。我检索问题并将其存储为字符串: NSString *htmlstring = @"If 3<em>x</em><sup><strong>2</strong></sup>&nbsp;+ 11<em>x</em>&nbsp;+ 6 $$\\ge$$&nbsp;0, then <em&g

我在SQLite数据库中存储了一组问题。对于数学科目,它们以html格式存储为公式/方程式。我检索问题并将其存储为字符串:

NSString *htmlstring = @"If 3<em>x</em><sup><strong>2</strong></sup>&nbsp;+ 11<em>x</em>&nbsp;+ 6 $$\\ge$$&nbsp;0, then <em>x</em>&nbsp;$$\\in $$";
此代码未按预期工作,输出为:

预期产出为:

在从数据库中获取数据或将html转换为纯文本时,我不知道它出了什么问题

更新

根据下面阿什米的回答,我发现文本是乳胶格式的。 如何将latex命令转换为符号现在是一个问题。有3种可能性:

  • 将Latex转换为HTML(按照Ashmi的建议),然后加载该HTML 在标签中
  • 将Latex转换为unicode字符以直接加载到标签中
  • 使用库(如果有的话)可能和数学一样

  • 请检查下面的代码您的HTML格式可能不正确,所以我只是改变HTML格式,并得到您想要的输出。有关在HTML中制作数学符号的更多信息,请查看下面的链接

    NSString*htmlstring=@“如果3x2+11x+6≥;0,则x€”;
    NSAttributedString*attrStr=[[NSAttributedString alloc]initWithData:[htmlstring dataUsingEncoding:NSInocDestringEncoding]选项:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}DocumentAttribute:nil错误:nil];
    NSLog(@“%@”,attrStr.string);
    

    我正在从数据库动态获取html字符串。但是,您提供的链接帮助我确定文本是LaTeX格式的。所以,需要找到一种方法从iOS中的LaTex命令中获取符号。是的,但您可以搜索html到LaTex格式并将其传递给字符串。
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
            questionLbl.attributedText = attrStr;
    
      NSString *htmlstring = @"If 3<em>x</em><sup><strong>2</strong></sup>&nbsp;+ 11<em>x</em>&nbsp;+ 6 &#x2265;0, then <em>x</em>&#x20AC";
    
      NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlstring dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    
      NSLog(@"%@",attrStr.string);