MathJaxView is a custom view extending WebView and offers offline support for MathJax for Android Apps.
You can add MathJaxView to your Android Studio project in two ways:
- Using a remote Maven repository (jCenter)
- Using AAR file downloaded from bintray
Add implementation 'io.github.sidvenu.mathjaxview:mathjaxview:1.0.7'
into dependencies section of your module build.gradle file.
You can download the latest version of MathView from Bintray.
- 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.
- Add dependency
Click File -> Project Structure -> Dependencies
, and then click the plus icon, select 3. Module Dependency
.
The usage of MathJaxView is similar to that of TextView. Refer to the sample app (MathJaxTest) for usage.
The default config is set to use single dollar symbols (view.setConfig(String)
method to change the configuration to anything of your
choice. The default config is set as follows:
config = "MathJax.Hub.Config({" +
" extensions: ['fast-preview.js']," +
" messageStyle: 'none'," +
" \"fast-preview\": {" +
" disabled: false" +
" }," +
" CommonHTML: {" +
" linebreaks: { automatic: true, width: \"container\" }" +
" }," +
" tex2jax: {" +
" inlineMath: [ ['$','$'] ]," +
" displayMath: [ ['$$','$$'] ]," +
" processEscapes: true" +
" }," +
" TeX: {" +
" extensions: [\"file:///android_asset/MathJax/extensions/TeX/mhchem.js\"]," +
" mhchem: {legacy: false}"+
" }" +
"});";
Make sure you add the extra MathJax assets that accompanies the change in config to your app (other than the one provided by the library).
You can do this by creating a MathJax folder in your assets folder that has the extra MathJax assets. The path to MathJax that you can use in your config can be: file:///android_asset/MathJax/extensions/TeX/mhchem.js
.
Sincere thanks to jianzhongli for their MathView project that served as an inspiration for this project.
How is it different from MathView?
- It features the latest MathJax version (v2.7.5).
- It does not have KaTeX, reducing the size of library. If you want KaTeX,there is a separate library for that: KaTeXView.
- Supports API level 15, targeting 100% of the Android devices as per documentation.
- Very small size - 1.36MB that was stripped down from 67.59MB of MathJax assets.
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. Furthermore, I've created a module that tests out the features of this library, called mathjaxtest. You can check it out for the library usage.
Please report any issues that you encountered, not limited to performance improvements and updating the MathJax assets.
PRs are an all-time welcome provided you follow the coding style similar to that already existing in the project.
This software is licensed under the Apache License, Version 2.0. Refer the license for more details.