flutterdartpdfsvglatex

How to Convert LaTeX to SVG for Rendering in a Flutter PDF?


I am working on a Flutter project where I need to render LaTeX mathematical equations in a PDF. My current approach involves converting LaTeX code to SVG and then embedding the SVG in the PDF. I found a tool online at https://viereck.ch/latex-to-svg/ that converts LaTeX to SVG, but I need to integrate this process into my Flutter app programmatically.

Here are my specific requirements and constraints:

The solution needs to be implemented in Dart/Flutter. It should be able to take a LaTeX string, convert it to an SVG, and then embed that SVG into a PDF document. Ideally, the solution should work offline without requiring access to external web services. Has anyone done something similar or can point me to a library or approach that can help achieve this? Any code examples or guidance would be greatly appreciated!

What I have tried: Using the tex package to convert TeX code, but I need to convert LaTeX to SVG specifically. Using the flutter_math package, but it does not support conversion to SVG directly. Looking into flutter_svg, but I need help with the LaTeX to SVG conversion part.


Solution

  • Based on the current state of Flutter and Dart libraries, it is not easily possible to convert LaTeX to SVG offline within a Flutter app using pure Dart code. There are no readily available packages that provide this specific functionality offline.

    To achieve this, you would likely need to implement your own LaTeX to SVG converter in Dart, which would be a complex undertaking, or use platform-specific native libraries through FFI (Foreign Function Interface).