KotliTeX is KaTeX's Android port, written in Kotlin.
This library provides com.karino2.kotlitex.view.MathExpressionSpan
and com.karino2.kotlitex.view.MarkdownView
.
Currently we are porting KaTeX 0.10.0 and canvas-latex (which doesn't have releases) mostly as is, while merging the 2 parts may be technically possible.
We believe that keeping the original structure makes future updates easier.
We basically have two part in our library. Expression tree building and rendering it.
Expression tree building is essentially the porting of KaTeX, while rendering is similar to canavs-latex (though this is sometime not the direct porting because of difference between HTML5 canvas and Android).
- Add functions/FunctionXXX.kt, which is port of KaTeX/src/functions/XX.js and call defineAll() from Parser.kt (Expression tree part)
- Add rendering logic under renderer/ someway
mathcal PR is typical and good starting point for investigate.
Use ktlint. ./gradlew format
format all .kt files with ktlint.
MathExpression Span now render inside TextView.
We provide MarkdownView class, which parse math expression of jekyll style asynchronously. (Though supported markup is only math expression and very limited).
- Make kotlitex-kotlitex of release flavor to create kotlitex-release.aar and place to your project as kotlitex.aar
- Import kotlitex.aar as official document says. https://developer.android.com/studio/projects/android-library
- Add build.gralde as following (We use kotlin version 1.3.20)
// kotlitex
implementation project(":kotlitex")
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1"
Then use io.github.karino2.kotlitex.view.MarkdownView
and call setMarkdown(text) to render math expression.
MainActivity.kt under sample directory show basic usage.
kotlitex itself is under MIT license. Also, our library contains other libraries.
- This library contain KaTeX font, which is under MIT license.
- Some data table and comment is from KaTeX, which is under MIT license.
- For rendering part, though code is from scratch, logic is very similar to Canvas-Latex, which is under MIT license.