开发者

generating equation png files based on mathematical input

开发者 https://www.devze.com 2023-01-06 20:44 出处:网络
I was wondering what options were available to generate .png based on the kind of input one feeds a graphing calculator.. so

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

generating equation png files based on mathematical input

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.


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

generating equation png files based on mathematical input

Another option is jsMath.


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.


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.


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:

generating equation png files based on mathematical input


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 :-)


There's a site EquationSheet.com that allows you to enter LaTeX and get back the URL of a generated image. Maybe your site could use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消