2

I'm looking for a way to convert my AsciiMath (or MathML) sources to SVG and/or PNG. I've found a nodeJS library for SVG conversion but calling that from Python is not very convenient and the output is not entirely satisfying.

Taking the fact I'd like to render mathematical formulas to svg/png it seems logical to look for a solution in math libraries (NumPy, SciPy, Pandas, Matplotlib, Sympy, etc...) but to no avail. All my google results combining all possible permutations of asciimath+mathml+svg+png lead to nothing which is strange.

Please recommend me either search patterns to find a solution or share your experiences/ideas to get this seemingly simple job done in Python.

All help would be highly appreciated!

Riverman
  • 503
  • 6
  • 17

2 Answers2

2

I just created ziamath for exactly this purpose. It comes bundled with the STIX math font, so no setup is required beyond the pip install, but it should also work with other math-enabled fonts. Pure-Python, so it does not need a Latex installation or anything else to work. This first version doesn't quite cover the full MathML specification, but the most useful parts are in there.

To bundle it into an app with something like PyInstaller, you'll need to make sure the STIX font gets included, but that should just be one line in the PyInstaller config.

Collin
  • 146
  • 4
0

I have used this for years without issues. It is written in python.

https://sourceforge.net/projects/svgmath/files/svgmath/0.3.3/

Kevin Brown
  • 8,805
  • 2
  • 20
  • 38
  • Sorry for the late response. Thanks for your suggestion, I've ran into this library too but it seems to require the user to define paths to fonts which seems to be very problematic for me because I'm intending to wrap my code into a package and packaging fonts seems to be a bad idea for me, but correct me if I'm wrong. – Riverman Mar 26 '19 at 11:59
  • I do not see how you can do it without using a font in fact very specific fonts that contain math symbols. – Kevin Brown Mar 26 '19 at 17:38