views:

169

answers:

6

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.

+9  A: 

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.

Greg Hewgill
cool! thx for posting
Jason S
+2  A: 

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.

John D. Cook
+2  A: 

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

Andrew Moylan
I am pretty sure the OP wants the PNG generation to happen automatically, preferably server-side, on a web page.
Andreas Rejbrand
I can't see how to give the manual on the way to tdo it in an expensive commercial software helps the implementation of the problem inside a programing language.
jsbueno
Well, the OP accidently tagged this question "Mathematica", so we cannot blame Andrew Morgan. It is very common that people unknowingly tag their question "Mathematica" (believeing the tag to be "Mathematics").
Andreas Rejbrand
@Andreas: He could use the Wolfram Alpha Webservice API (same company as Mathematica). It's not free, though.
Daniel Stutzbach
@Daniel Stutzbach If he is not planning a commercial app, he could post http straight to wolfram alpha and get the formatted equation back as a result.
belisarius
+1  A: 

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

jsbueno
+2  A: 

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.

Jouni K. Seppänen
A: 

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.

duffymo