美文网首页iOS 知识点iOS学习iOS Developer
基于Latex转码的iOS数学,物理,化学公式以及图形渲染库--

基于Latex转码的iOS数学,物理,化学公式以及图形渲染库--

作者: CodingSha | 来源:发表于2016-12-01 16:45 被阅读3889次

Latex

latex是目前比较全面用于将数学,物理,化学公式转换成格式化字符的形式,现在也是各大主流教育类app的主要数据存储形式.

Katex

Katex是基于js实现的渲染Latex代码的库,据称是目前渲染效率最好,性能最优的公式渲染引擎.

MathKit

基于Katex渲染库,并用YYText进行异步排版,完美实现了理科公式非数据化数据的处理以及视图展示.MathKit github链接

MathKit强在哪?

  • 强劲的渲染性能
  • 非常简单的代码
  • 快速集成
  • 极少的依赖库
  • 一个类,一个属性,一句话解决理科公式渲染

如何使用

#import "MathSubjectView.h"
NSString*str =@"4.<math>\\displaystyle= \\frac{k(k+1)}{2}+k+1</math>这个大家知道是什么吗?请写出答案吧";
MathSubjectView*subject = [[MathSubjectViewalloc]initWithFrame:CGRectMake(10,100,self.view.bounds.size.width-20,0)];
subject.font= [UIFontsystemFontOfSize:12];
subject.testStr= str;
[self.viewaddSubview:subject];

举个例子

Snip20161201_18.png
链接地址:https://github.com/CodingSha/SPMathKit

GitHub介绍


MathKit

What MathKit can do?

  • It will render you your math, physics, chemistry or any science formula,Geometric graphics and pictures, as well as general text.

  • MathKit used by the rendering engine from the current fastest performance of the best JavaScript mathematical formula rendering engine

  • MathKit the mathematical formula derived from the code is very simple and very easy to store the Latex code

Based on this, we believe that it will become the most popular science formula and graphics rendering Library

Why you need MathKit?

  • Strong rendering performance
  • Very simple code
  • Fast integration
  • Minimal dependency Library

Usage

  1. Download all the files in the MathKit subdirectory.
  2. Add the source files to your Xcode project.
  3. Link with required frameworks:
  1. Import MathSubjectView.h.
  2. Initialization of an instance object, and give the testStr attribute assignment, where the object will be copied to the mixture of arbitrary science formulas and pictures of the string.
    Note: Here's the formula in the string need to use a tag similar to <math></math> wrapped up, and the picture will need to use a tag similar to <image></image> wrapped up, so as to be recognized
  3. Add the instance object to your view.

If you still do not know how to use it, then download the code to see it, the package has my prepared sample demo.

相关文章

网友评论

  • LD_左岸:我把您的这段代码
    NSString*str =@"4.<math>\\displaystyle= \\frac{k(k+1)}{2}+k+1</math>这个大家知道是什么吗?请写出答案吧";
    MathSubjectView*subject = [[MathSubjectViewalloc]initWithFrame:CGRectMake(10,100,self.view.bounds.size.width-20,0)];
    subject.font= [UIFontsystemFontOfSize:12];
    subject.testStr= str;
    [self.viewaddSubview:subject];

    拷贝到您的demo的ViewDidLoad里 并且把您之前写在ViewDidLoad里的代码进行了删除
    但是没效果呢 什么都没有出现
    我是否可以理解为相当于服务器把HTML5里面的MathML标签里的内容返回给我 然后我在本地把这个body组装成一个具有header的完整的HTML字符串 然后WKWebView去加载这个H5字符串 我看洋葱数学和狸米里都有类似功能 但是他们的交互性都非常好 比如我在键盘上输入开根号或者其他数学符号 都能实时显示到WebView中
    请大神指点一二..
    CodingSha:@左岸__ wk里添加了katex用于解析latex代码,基本和你理解的一样。mathml也是支持的,中间有转码。洋葱那样的一般都是直接使用h5写的,有实时显示。如果你会,可以试试。我封装的这个性能也不太好。你可以直接在github里直接搜索katex看看有没有帮助
  • 今年我25:大神 支不支持 tex格式呀
    CodingSha:@今年我25 latex是tex的扩展,应该多数都是支持的,不过肯定会有遗漏的,因为库还在完善
  • CodingSha:最近又扩展了对MathML的支持
  • 加双芋:老沙:eyes:
    CodingSha:@木卜小兑 卧槽,我还睡觉呢,被你吵醒了
  • 卟师:我能转载分享吗?我会标注上作者和出处的
    CodingSha:@卟师 好的👌
    卟师:@CodingSha 我会放在微信公众号:iOS面向编码
    你可以看一下
    CodingSha:@卟师 注明转载,然后链接发我一下,谢谢
  • d5bdb8e52d81:性能是不错,比MathJax渲染速度快很多,最近正好要做教育类app,收藏了,先感谢一下,另外,提一个意见,您封装的有点太多了,扩展性可能会受限制,虽然这样用起来确实非常简单
    CodingSha:@沙少盼 嗯,后续会继续维护,尽量再丰富和扩展一下功能,现在基本够用了,谢谢收藏喜欢

本文标题:基于Latex转码的iOS数学,物理,化学公式以及图形渲染库--

本文链接:https://www.haomeiwen.com/subject/ognxmttx.html