iOS開源 - 數學,物理,化學公式以及圖形渲染庫
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];
舉個例子
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
- Download all the files in the MathKit subdirectory.
- Add the source files to your Xcode project.
- Link with required frameworks:
- CoreText
- UIKit
- SDWebImage
- YYText
- Import
MathSubjectView.h
. - 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 - 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.
- — SPMathKit - Render math exercises for your view. Contains the rendering of mathematical formulas and mathematical graphics, as well as the general text