Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render Latex in Flutter, offline

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.

like image 447
Mr.B Fellow Avatar asked May 13 '20 10:05

Mr.B Fellow


2 Answers

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)))
like image 105
TheOneWithTheBraid Avatar answered Oct 09 '22 17:10

TheOneWithTheBraid


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');
like image 43
creativecreatorormaybenot Avatar answered Oct 09 '22 16:10

creativecreatorormaybenot