17

我对此进行了很长时间的研究,我知道这类问题已经得到解答。但我找不到正确的答案来展示如何在 Android 应用程序中实际处理数学公式。如果在 Android 项目中不包含大量(5~20MB)文件,似乎无法像 MATHML 那样解析和显示数学公式脚本。我查看了在 Android 中经常提到的 JEuclid 和 MathJax,但我发现它们属于这一类。

所以在这一点上,我能想到的唯一方法是将这些公式中的每一个都放在一个图像文件中并在 Android 上显示它。但在实践中,这个手动过程真的很慢。我确信这不是正确的方法。

所以我不得不再次问这个问题。如何在您的 Android 应用程序中实际显示数学公式?

4

4 回答 4

4

您不能在 android 中将数学公式设置为 TextView。您必须使用可以显示数学公式的 WebView。有关更多信息,请参见mathjax。如果你想为 android 显示,那么这里是你可以在你的项目中实现的库。mathjaxwebview

于 2016-05-12T17:43:59.860 回答
3

如果您想解析 Tex(内联模式和显示模式)格式和 ASCII 数学格式,您可以使用此链接。我使用此链接中给出的上述数学视图来显示公式。它就像从官方下载的 mathjax 中添加了一个魅力站点并获取字体文件夹并将其放在您的资产文件夹中。它肯定会奏效。

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

下载链接上方的数学视图表格。

于 2017-08-10T11:23:56.203 回答
2

用于包装 latex-rendering-js-library的WebView库(例如thisthisthis)不能很好地与 the 配合使用,RecyclerView并且会使应用程序变慢。他们甚至没有更新 js 库。


最后,我找到了“ noties/jlatexmath-android ”,它使用的是“ opencollab/jlatexmath ”本机Java 库。它速度快,可以很容易地与RecyclerView.

示例用法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)

您还可以将它用作“noties/Markwon”的扩展,这是一个适用于 Android 的 Markdown 库。详细信息可以在这里找到。

示例用法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)
于 2021-10-12T18:45:30.237 回答
0

您可以使用 MathType 来实现。

但是您要显示的数据必须是 MathType 格式

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

于 2020-06-04T09:49:01.037 回答