Skip to content

oppia/kotlitex

 
 

Repository files navigation

KotliTeX

Build Status

KotliTeX is KaTeX's Android port, written in Kotlin.

This library provides com.karino2.kotlitex.view.MathExpressionSpan and com.karino2.kotlitex.view.MarkdownView.

Porting Guidelines

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.

How to port new function

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).

  1. Add functions/FunctionXXX.kt, which is port of KaTeX/src/functions/XX.js and call defineAll() from Parser.kt (Expression tree part)
  2. Add rendering logic under renderer/ someway

mathcal PR is typical and good starting point for investigate.

Coding Style

Use ktlint. ./gradlew format format all .kt files with ktlint.

Current status (2019/04/09)

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).

Sccreen Shot

Include kotlitex to other project

  1. Make kotlitex-kotlitex of release flavor to create kotlitex-release.aar and place to your project as kotlitex.aar
  2. Import kotlitex.aar as official document says. https://developer.android.com/studio/projects/android-library
  3. 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.

License

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.

About

katex porting for kotlin.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 99.3%
  • Other 0.7%