A LaTeX rendering library for Android

Overview

logo

Library for displaying LaTeX formulas on Android. It use cLaTeXMath to parse and render LaTeX code. The picture below demonstrate the demo application.

demo

Installation

Library is available in jcenter repository, add this script to your build.gradle file to install:

implementation 'io.nano:android-tex:1.0.0'

ProGuard

Add the following rule to your proguard config file:

-keep class io.nano.tex.**

How to use

First, initialize the library:

// ... code inside an Activity or Application
@override
public void onCreate() {
    // ... some other code
    // Initialize the LaTeX engine. Call of this function will copy the 
    // "TeX resources" from apk into the data files directory of the
    // host application, and parse the "TeX resources", it may takes a
    // long time, you may call it from a background thread.
    if (!LaTeX.isInitialized()) {
        LaTeX.instance().init(getApplicationContext());
    }
}

Then, parse the given LaTeX code:

String code = "\\int_{now}^{\\infty} \\text{Keep trying}";
TeXRender r = LaTeX.instance().parse(
    code,        // LaTeX code to parse
    720,         // logical width of the graphics context (in pixel)
    20,          // font size
    10,          // space between 2 lines (in pixel)
    Color.DKGRAY // foreground color
);

Last, just draw it:

@override
protected void onDraw(Canvas canvas) {
    Graphics2D g2 = new Graphics2D();
    g2.setCanvas(canvas);
    // draw the formula on the coordinate (10, 10)
    r.draw(g2, 10, 10);
}

Very simple. For more details, please check out the demo app of this project.

Build by yourself

First make sure you have a NDK that the version must be >=4.9 installed. Then add the following script to your local.properties file:

ndk.dir=/your/NDK/dir

Update the latest C++ implementation using git:

git submodule init --recursive
git submodule update --remote

Now everything is OK, just build it.

License

This project is under the Apache-2.0

Copyright 2018 Nano Michael

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Android Library to implement simple touch/tap/swipe gestures
Android Library to implement simple touch/tap/swipe gestures

SimpleFingerGestures An android library to implement simple 1 or 2 finger gestures easily Example Library The library is inside the libSFG folder Samp

Useful library to use custom fonts in your android app
Useful library to use custom fonts in your android app

EasyFonts A simple and useful android library to use custom fonts in android apps without adding fonts into asset/resource folder.Also by using this l

Android library which allows you to swipe down from an activity to close it.
Android library which allows you to swipe down from an activity to close it.

Android Sliding Activity Library Easily create activities that can slide vertically on the screen and fit well into the Material Design age. Features

This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.
An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.

ShortcutBadger: The ShortcutBadger makes your Android App show the count of unread messages as a badge on your App shortcut! Supported launchers: Sony

Android Library to build a UI Card
Android Library to build a UI Card

Card Library Travis master: Travis dev: Card Library provides an easy way to display a UI Card using the Official Google CardView in your Android app.

A horizontal view scroller library for Android
A horizontal view scroller library for Android

View Flow for Android ViewFlow is an Android UI widget providing a horizontally scrollable ViewGroup with items populated from an Adapter. Scroll down

[] Android library that provides a file explorer to let users select files on external storage.
[] Android library that provides a file explorer to let users select files on external storage.

aFileChooser - Android File Chooser aFileChooser is an Android Library Project that simplifies the process of presenting a file chooser on Android 2.1

Android library for multiple snapping of RecyclerView
Android library for multiple snapping of RecyclerView

MultiSnapRecyclerView Gradle dependencies { implementation 'com.github.takusemba:multisnaprecyclerview:x.x.x' } Features This is an Android Libra

Comments
  • 设置字体后,文本宽度超过屏幕宽度,没有换行!

    设置字体后,文本宽度超过屏幕宽度,没有换行!

    大佬: 我虽然clone了项目,可惜不会C++,还是没能解决如下bug: 魅族16S, 1080*1920.

    1. 设置文本 tv_latex.setLaTeX("sqrt[3]{(x-y)^3}=x^2-3*xy+y^2 \overline{a+b}")
    2. 修改显示宽度 , textSize = 40 public void setLaTeX(String ltx) { int w = getWidth(); if (w == 0) w = 1080; // 这里设置屏幕宽度 render = LaTeX.instance().parse(ltx, w, textSize, 10, Color.parseColor("#6200EE")); requestLayout(); }
    3. 调用设置文字大小方法 tv_latex.setTextSize(80) // 最开始文本大小设置的是40, 现在修改为80

    屏幕显示不完整,即没有换行显示! 希望大佬修改下这bug!

    help wanted 
    opened by Jooyer 4
  • 本库兼容LaTex原生语法问题

    本库兼容LaTex原生语法问题

    大佬: 早上好! 我拷贝一段LaTex原生语法如下: \documentclass{article} \usepackage{ctex} \begin{document} 你好,LaTeX \end{document}

    ,然后利用本demo中的TexView的setLaTeX(),发现无法正常显示,大佬方便留个微信号/QQ号,我向大佬请教下,我的 微信/QQ 均是 712952521 .

    help wanted 
    opened by Jooyer 2
Owner
Nano
Nano
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Enrique López Mañas 3.6k Dec 29, 2022
Android library providing bread crumbs to the support library fragments.

Hansel And Gretel Android library providing bread crumbs for compatibility fragments. Usage For a working implementation of this project see the sampl

Jake Wharton 163 Nov 25, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)

Wizard Pager Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (ht

Julián Suárez 520 Nov 11, 2022
Make your native android Toasts Fancy. A library that takes the standard Android toast to the next level with a variety of styling options. Style your toast from code.

FancyToast-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ... ma

Shashank Singhal 1.2k Dec 26, 2022
Make your native android Dialog Fancy. A library that takes the standard Android Dialog to the next level with a variety of styling options. Style your dialog from code.

FancyAlertDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ..

Shashank Singhal 350 Dec 9, 2022
A Tinder-like Android library to create the swipe cards effect. You can swipe left or right to like or dislike the content.

Swipecards Travis master: A Tinder-like cards effect as of August 2014. You can swipe left or right to like or dislike the content. The library create

Dionysis Lorentzos 2.3k Dec 9, 2022
A Material design Android pincode library. Supports Fingerprint.

LolliPin A Lollipop material design styled android pincode library (API 14+) To include in your project, add this to your build.gradle file: //Loll

Omada Health 1.6k Nov 25, 2022