erfz / MathJaxView

A library to render MathJax offline in Android devices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MathJaxView

API Download

MathJaxView is a custom view extending WebView and offers offline support for MathJax that renders faster than MathView with its support for fast-preview.

Setup

You can add MathJaxView to your Android Studio project in two ways:

  1. Using a remote Maven repository (jCenter)
  2. Using AAR file downloaded from bintray

1. Setup from a remote Maven repository (jcenter)

Add implementation 'io.github.sidvenu.mathjaxview:mathjaxview:1.0.5' into dependencies section of your module build.gradle file. For example:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:23.0.0'
    implementation 'io.github.sidvenu.mathjaxview:mathjaxview:1.0.5'
}

2. Setup from local .aar file

You can download the latest version of MathView from Bintray.

  1. Import the module from local .aar file

Click File - New - New Module (yes, not Import Module) -> Import .JAR/.AAR Package, and find out where the file located.

  1. Add dependency

Click File -> Project Structure -> Dependencies, and then click the plus icon, select 3. Module Dependency.

Usage

The usage of MathJaxView is similar to that of TextView

XML
<io.github.sidvenu.mathjaxview.MathJaxView
    android:id="@+id/formula"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="$$2^x=15$$"/>
Java
public class MainActivity extends AppCompatActivity {
    MathJaxView view;
    String tex = "Inline formula:" +
            " $ax^2 + bx + c = 0$" +
            "or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        super.onResume();

        view = findViewById(R.id.formula);
        view.setText(tex);
    }
}
MathJax configuration

The default config is set to use single dollar symbols ($) for inline formula and double dollar symbols ($$) for displayed formula. You can use the view.setConfig(String) method to change the configuration to anything of your choice.

Documentation

The code of MathJaxView (a single small file) is well documented and anyone can easily understand it. Please view the code and try to understand it yourself. If you don't, please raise a issue with the help wanted label.

Issues

Please report any issues that you encountered, not limited to performance improvements and updating the MathJax assets.

Pull Requests

PRs are an all-time welcome provided you follow the coding style similar to that already existing in the project.

Thanks

A sincere thanks to kexanie for their MathView project that served as an inspiration for this project.

License

This software is licensed under the Apache License, Version 2.0. Refer the license for more details.

About

A library to render MathJax offline in Android devices

License:Other


Languages

Language:Java 100.0%