How to render Latex in Flutter, offline

1,968

Solution 1

You could use katex_flutter.

katex_flutter is an alternative to flutter_tex which offers actually exactly the same functionality as flutter_tex does. There are some minor differences under the hood: For example katex_flutter does not require an internet connection and uses KaTeX instead of MathJax for rendering equations.

Please read the full instructions in pub.dev about how to set up katex_flutter for your project.

A simple example how to use it:

import 'package:katex_flutter/katex_flutter.dart';

...

return KaTeX(laTeXCode: Text("\\alpha", style: Theme.of(context)
                      .textTheme
                      .bodyText1
                      .copyWith(color: Colors.red)))

Solution 2

You can now also try CaTeX (full disclosure: I am an author).
It does not depend on any web views or JavaScript and renders the equations "natively" in Flutter.

Note: the package is a pre-release, so you will not be able to use it for every formula.

import 'package:catex/catex.dart';

Widget build(BuildContext context) => CaTeX(r'\text{Your equation: } 40 + 2 = 42');
Share:
1,968
Admin
Author by

Admin

Updated on December 20, 2022

Comments

  • Admin
    Admin over 1 year

    There is a package called flutter_tex. But, it required internet access. I want to render Latex without using internet. How to render Latex in flutter, without using internet.