How to practically display math formula in Android How to practically display math formula in Android android android

How to practically display math formula in Android


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


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.


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 symbolsimplementation "ru.noties:jlatexmath-android-font-cyrillic:$jlatexmath_version"// for Greek symbolsimplementation "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)