搜索插件、代码仓与 APP 分类

flutter_math_fork 封面
插件详情v0.7.4

flutter_math_fork

使用纯 Dart 和 Flutter 快速且高质量地渲染 TeX 数学公式。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
33.1万
喜欢数
172
Pub 分数
140

安装插件

flutter pub add flutter_math_fork

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个高性能的 Dart 和 Flutter 包,用于精确且快速地渲染 TeX 数学方程。作为 flutter_math 的分支构建,它允许在 Flutter 应用中无缝集成数学表达式,使用纯 Dart 实现,确保与所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)兼容。适用于教育类应用、科学工具以及任何需要准确显示方程的应用。

适合场景

  • 教育类应用
  • 科学计算器
  • 数学内容渲染
  • 互动式学习平台
  • 文档查看器

主要特点

  • 纯 Dart 实现
  • 高速渲染
  • 跨平台支持
  • TeX 语法兼容性
  • 可自定义样式

适合对象

  • 开发计算密集型应用的开发者
  • 教育技术项目
  • 需要精确显示方程的应用程序
  • 寻求轻量级数学渲染的Flutter开发者

使用建议

  • 仅限基本的 TeX 功能
  • 不支持高级 LaTeX 包
  • 渲染质量取决于字体的可用性
  • 可能需要对复杂方程进行调整

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Math

Build Status codecov Pub Version

⚠ fork

This is a fork of flutter_math addressing compatibility problems while flutter_math is not being maintained.


Math equation rendering in pure Dart & Flutter.

This project aims to achieve maximum compatibility and fidelity with regard to the KaTeX project, while maintaining the performance advantage of Dart and Flutter. A further UnicodeMath-style equation editing support will be experimented in the future.

The TeX parser is a Dart port of the KaTeX parser. There are only a few unsupported features and parsing differences compared to the original KaTeX parser. List of some unsupported features can be found here.

Online Demo

Rendering Samples

x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Example1

i\hbar\frac{\partial}{\partial t}\Psi(\vec x,t) = -\frac{\hbar}{2m}\nabla^2\Psi(\vec x,t)+ V(\vec x)\Psi(\vec x,t)

Example2

\hat f(\xi) = \int_{-\infty}^\infty f(x)e^{- 2\pi i \xi x}\mathrm{d}x

Example3

How to use

Add flutter_math to your pubspec.yaml dependencies

Mobile

Currently only Android platform has been tested. If you encounter any issues with iOS, please file them.

Web

Web support is added in v0.1.6. It is tested for DomCanvas backend. In general it should behave largely the same with mobile. It is expected to break with CanvasKit backend. Check out the Online Demo

API usage (v0.2.0)

The usage is straightforward. Just Math.tex(r'\frac a b'). There is also optional arguments of TexParserSettings settings, which corresponds to Settings in KaTeX and support a subset of its features.

Display-style equations:

Math.tex(r'\frac a b', mathStyle: MathStyle.display) // Default

In-line equations

Math.tex(r'\frac a b', mathStyle: MathStyle.text)

The default size of the equation is obtained from the build context. If you wish to specify the size, you can use textStyle. Note: this parameter will also change how big 1cm/1pt/1inch is rendered on the screen. If you wish to specify the size of those absolute units, use logicalPpi

Math.tex(
  r'\frac a b',
  textStyle: TextStyle(fontSize: 42),
  // logicalPpi: MathOptions.defaultLogicalPpiFor(42),
)

There is also a selectable variant SelectableMath that creates selectable and copy-able equations on both mobile and web. (EXPERIMENTAL) Users can select part of the equation and obtain the encoded TeX strings. The usage is similar to Flutter's SelectableText.

SelectableMath.tex(r'\frac a b', textStyle: TextStyle(fontSize: 42))

If you would like to display custom styled error message, you should use onErrorFallback parameter. You can also process the errors in this function. But beware this function is called in build function.

Math.tex(
  r'\garbled $tring', 
  textStyle: TextStyle(color: Colors.green),
  onErrorFallback: (err) => Container(
    color: Colors.red,
    child: Text(err.messageWithType, style: TextStyle(color: Colors.yellow)),
  ),
)

If you wish to have more granularity dealing with equations, you can manually invoke the parser and supply AST into the widget.

SyntaxTree ast;
try {
  ast = SyntaxTree(greenRoot: TexParser(r'\frac a b', TexParserSettings()).parse());
} on ParseException catch (e) {
  // Handle my error here
}

SelectableMath(
  ast: ast,
  mathStyle: MathStyle.text,
  textStyle: TextStyle(fontSize: 42),
)

Line Breaking

Credits

This project is possible thanks to the inspirations and resources from the KaTeX Project, MathJax, Zefyr, and CaTeX.

Goals

  • [x] : TeX math parsing (See design doc)
  • [x] : AST rendering in flutter
  • [x] : Selectable widget
  • [x] : TeX output (WIP)
  • [ ] : UnicodeMath parsing and encoding
  • [ ] : UnicodeMath-style editing
  • [ ] : Breakable equations
  • [ ] : MathML parsing and encoding

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目