Giter VIP home page Giter VIP logo

androidlatexmath's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.