views:

610

answers:

4

Hi

I'd like to generate an image file showing some mathematical expression, taking a String like "(x+a)^n=∑_(k=0)^n" as input and getting a more (human) readable image file as output. AFAIK stuff like that is used in Wikipedia for example. Are there maybe any java libraries that do that?

Or maybe I use the wrong approach. What would you do if the requirement was to enable pasting of formulas from MS Word into an HTML-document? I'd ask the user to just make a screenshot himself, but that would be the lazy way^^

Edit: Thanks for the answers so far, but I really do not control the input. What I get is some messy Word-style formula, not clean latex-formatted one.

Edit2: http://www.panschk.de/text.tex Looks a bit like LaTeX doesn't it? That's what I get when I do clipboard.getContents(RTFTransfer.getInstance()) after having pasted a formula from Word07. Thanks again for the answers.

+6  A: 

First and foremost you should familiarize yourself with TeX (and LaTeX) - a famous typesetting system created by Donald Knuth. Typesetting mathematical formulae is an advanced topic with many opinions and much attention to detail - therefore use something that builds upon TeX. That way you are sure to get it right ;-)

Edit: Take a look at texvc

It can output to PNG, HTML, MathML. Check out the README

Edit #2 Convert that messy Word-stuff to TeX or MathML?

toxvaerd
Perhaps showing in html with http://wordpress.org/extend/plugins/easy-latex/
Stephen Denne
A: 

What you're looking for is Latex.

MikTex is a nice little application for churning out images using LaTeX.

I'd like to look into creating them on-the-fly though...

Neil McKeown
A: 

Steer clear of LaTeX. Seriously.

Check out JEuclid. It can convert MathML expressions into images.

cletus
That depends how much you care about typesetting... From the screenshots, it doesn't look like JEuclid care much about that aspect ;-)
toxvaerd
A: 

My colleague found a surprisingly simple solution for this very specific problem: When you copy formulas from Word2007, they are also stored as "HTML" in the Clipboard. As representing formulas in HTML isn't easy neither, Word just creates a temporary image file on the fly and embeds it into the HTML-code. You can then simply take the temporary formula-image and copy it somewhere else. Problem solved;)

panschk