[Feature request]: Latex Support
Which feature is your request related to?
markdown
Describe your request for enhancements!
When text is wrapped by $ or $$, render it in Latex (either through Katex or MathJax).
Additional context
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Good idea. Maybe also add it in rich text mode, but I'm currently not sure how
I searched a bit how we could make it and found this:
- https://pub.dev/packages/flutter_math_fork (but isn't really active maintained)
- https://pub.dev/packages/flutter_tex (but has performance issues when using many latex elements)
- Use katex directly: https://katex.org/, for this we also need to add a javascript engine to the app https://github.com/abner/flutter_js which could add up the app size
- Use mathjax directly https://www.mathjax.org, for this we also need to add a javascript engine to the app https://github.com/abner/flutter_js which could add up the app size
Adding a javascript engine could also help the app adding new libraries, maybe enhancing the current pdf status. Then we could use pdf.js directly and support more features. But it also adds up the app size (~ 5mb)
Just a note (not sure if notes like this are appreciated or annoying?):
I would make heavy use of LaTeX if it were available. I'm planning on using Butterfly to make a collection of math courses on YouTube.
Yeah, I'm currently evaluating how I could add it on all platforms without having any difference. I think the javascript version with katex is the best option on all platforms combined with https://crates.io/crates/boa_engine. I'm just thinking if this could also be the option to add extension support for butterfly.
If I understood these things more deeply I'd offer to help -- but I think all I can do is promise to test it if you ever get it working! In any case I appreciate the work.
But I've used KaTeX directly in web pages and it works great. So if it can be integrated, I'd be very happy with that.
Added to the 2.4 plan: I will use the flutter_math_fork and try to render the widget as a png and then put it inside the canvas
I tried it multiple hours and didn't get it working. TextPainter only gives "Placeholder positions" and you need to handle how the widget is rendered. These render logic is inside the low level flutter architecture which I can't figure out currently...
I will publish the branch for now here for anyone who wants to help here.
Found out how to render flutter widgets. Lets see if this is working... https://github.com/ABausG/home_widget/blob/main/packages%2Fhome_widget%2Flib%2Fsrc%2Fhome_widget.dart#L156
Latex is rendering 🎉
i need to build something around it but it looks good :)
See https://github.com/LinwoodDev/Butterfly/pull/881 for more updates
I will make an incremental update out of that. I will first focus on Markdown, then I will add latex functionality in rich text
Added support for rich text in https://github.com/LinwoodDev/Butterfly/commit/feaf2310e3740a0704cb9000c4127e3f9a07ccb8