Coder Social home page Coder Social logo

hiru-vn / flutter_math_fork Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simpleclub-extended/flutter_math_fork

0.0 0.0 0.0 1.62 MB

Just a small update

License: Apache License 2.0

Ruby 0.11% Objective-C 0.01% Kotlin 0.01% Dart 99.75% Swift 0.03% HTML 0.09%

flutter_math_fork's Introduction

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.

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),
)

Credits

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

Goals

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

flutter_math_fork's People

Contributors

znjameswu avatar creativecreatorormaybenot avatar ichordedionysos avatar kamil-simple avatar millerovv avatar p-mazhnik avatar edhom avatar hardiklakhalani avatar sese-schneider avatar walsha2 avatar olof-dev avatar fzyzcjy avatar yeomdonguk avatar michalsrutek avatar jigneshworld avatar jankolancer avatar jeuler avatar skyost avatar the-redhat avatar douglasserena avatar alihassan143 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.