Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generating equation png files based on mathematical input

I was wondering what options were available to generate .png based on the kind of input one feeds a graphing calculator.. so

(y^2 + 5x + 3) / ((3x + 3) + 5y + 18)

would return

alt text

The only thing I've found so far is texvc in mediawiki, but it seems overkill to get the whole mediawiki for one of it's modules.

like image 765
tipu Avatar asked Jul 10 '10 11:07

tipu


5 Answers

The Google Chart API has this function, it takes TeX input and creates an output image.

http://chart.apis.google.com/chart?cht=tx&chl=%5Cfrac%7By%5E2%2B5x%2B3%7D%7B(3x%2B3)%2B5y%2B18%7D

Another option is jsMath.

like image 193
Greg Hewgill Avatar answered Oct 18 '22 21:10

Greg Hewgill


There's dvipng that ships with TeX. It has a lot of parameters to twiddle. That's good if you want such control, but bad if you'd like something simpler to use.

like image 28
John D. Cook Avatar answered Oct 18 '22 20:10

John D. Cook


Matplotlib's mathtext engine can turn a subset of TeX into images. See specifically MathtextBackendBitmap for a solution that does not require the other matplotlib backends.

If that doesn't help, matplotlib also has code that calls TeX and dvipng.

Sage could also include some useful code.

like image 27
Jouni K. Seppänen Avatar answered Oct 18 '22 21:10

Jouni K. Seppänen


An option using Mathematica is:

Export["etc.png", 
 Rasterize[TraditionalForm[HoldForm[(y^2 + 5 x + 3)/((3 x + 3) + 5 y + 18)]]]]

which produces this image file:

alt text

like image 25
Andrew Moylan Avatar answered Oct 18 '22 22:10

Andrew Moylan


As many people cited, TeX might be the most straightforward path to take there - Searching for python tex yields some possibilities, one of the simpler might be: http://pypi.python.org/pypi/tex/1.5

It is just a wrapper to call Tex as a subprocess, and have a "dvi" file -- you'd still have to run dvipng (which as @JohnCook puts it, comes with TeX) to get your png file.

The drawback is that you have to set up the full TeX tool chain (not a problem on most Linux distributions).

Anotherway would be to get hold of MathMl rendering libraries - but then, you'd have to assemble the MathML markup for yur equation. Thre is a promising Python MathML to SVGmodule here: http://sourceforge.net/projects/svgmath/ That should have less librarie dependencies, and depending on your purposes, SVG might be more suitable than .PNG for equations. Else, ask stackoverflow again to go from .svg to .png in Python :-)

like image 27
jsbueno Avatar answered Oct 18 '22 22:10

jsbueno