18

I researched on this for quite a while and I know this kind of questions already answered. But I couldn't find a right answer showing how to practically deal with math formula in Android app. Without including large amount (5~20MB) of files in the Android project, it seems that there is no way to parse & display math formula script like MATHML. I looked at JEuclid and MathJax that were mentioned a lot for Android but I found them in this category.

So at this point, the only way I can think of is to take each of those formula in a image file and display it on Android. But in practice, that manual process is really slow. I am sure this is not a right way.

So I have to ask this again. How to practically display math formula in your Android app?

VividD
  • 10,456
  • 6
  • 64
  • 111
Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240
  • maybe these links for [mathML on Java/Android](http://stackoverflow.com/a/1792641/94363) can help – rds Dec 02 '11 at 16:31
  • 1
    @rds Ironically, that's one of the answers I particularly didn't like. The question was clearly for android device, but that answer mentioned java libraries Android app cannot utilize. Refer to this for detail: http://stackoverflow.com/questions/5767409/math-or-latex-engine-for-droid-phones – Tae-Sung Shin Dec 02 '11 at 16:43

4 Answers4

4

You can not set maths formula to TextView in android. You have to use WebView in which you can display maths formulae. See mathjax for more information. if you want to display for android then here is library you can implement in your project. mathjaxwebview

Vinayak Mestri
  • 359
  • 2
  • 7
3

If you want to parse Tex(Inline mode and display mode) formats and ASCII math format you can use this link .I used the above math view given in this link to display formula.It worked like a charm adding to that download mathjax from official site and get fonts folder and put it in your assets folder. It will definitely work.

https://github.com/Nishant-Pathak/MathView

download math view form above link.

Senthilvel S
  • 331
  • 1
  • 7
  • 21
2

The libraries which are using WebView to wrap latex-rendering-js-library (e.g., this, this and this), are not working well with the RecyclerView and will make the app slow. And they are not even updating the js libraries.


Finally, I found "noties/jlatexmath-android", which is using "opencollab/jlatexmath" native Java library. It is fast and can be easily used with RecyclerView.

Sample usage of JLatexMathView:

implementation "ru.noties:jlatexmath-android:$jlatexmath_version"
// for Cyrillic symbols
implementation "ru.noties:jlatexmath-android-font-cyrillic:$jlatexmath_version"
// for Greek symbols
implementation "ru.noties:jlatexmath-android-font-greek:$jlatexmath_version"
<ru.noties.jlatexmath.JLatexMathView
    android:id="@+id/j_latex_math_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dip"
    android:background="@color/white"
    app:jlmv_alignVertical="center"
    app:jlmv_alignHorizontal="center"
    app:jlmv_textSize="16sp" />
val latexText = "\$\$f(x)=(x+a)(x+b)\$\$"

binding.jLatexMathView.setLatex(latexText)

You can also use it as an extension of "noties/Markwon", a Markdown library for Android. Details can be found here.

Sample Usage of Markwon:

implementation "io.noties.markwon:core:$markwon_version"
implementation "io.noties.markwon:ext-latex:$markwon_version"
implementation "io.noties.markwon:inline-parser:$markwon_version"
<TextView
    android:id="@+id/tv_markdown"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
val markwon = Markwon.builder(requireContext())
    .usePlugin(MarkwonInlineParserPlugin.create())
    .usePlugin(JLatexMathPlugin.create(binding.tvMarkdown.textSize) { builder ->
        // ENABLE inlines
        builder.inlinesEnabled(true)
    })
    .build()

val latexText = "Example: \$\$f(x)=(x+a)(x+b)\$\$"

markwon.setMarkdown(binding.tvMarkdown, latexText)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Mahmudul Hasan Shohag
  • 2,203
  • 1
  • 22
  • 30
0

You can implement with MathType.

But your data for display must be in MathType format

https://docs.wiris.com/en/mathtype/mathtype_web/sdk/mobile-apps

Dara Vichit
  • 590
  • 1
  • 7
  • 15