4

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
panschk
  • 3,228
  • 3
  • 24
  • 20
  • It's very likely to be easier to convert messy to LaTeX rather than implement LaTeX from scratch - it took Knuth years. – Pete Kirkham Feb 17 '09 at 10:20
  • good point. I also just realised that what I get from the RTFTransfer class when accessing the clipboard looks a lot like LaTeX with some gibberish in between. So I might be halfway there;) – panschk Feb 17 '09 at 10:51
  • That is RTF, isn't it? Look at http://www.tug.org/utilities/texconv/pctotex.html on how to convert from RTF to LaTeX. – toxvaerd Feb 17 '09 at 11:06
  • thanks again. Looks like an awful lot of work to make that happen though. Looks like there is no really simple way to do it, without editing and recompiling stuff in languages I don't really know :/ May not be worth the effort :D – panschk Feb 17 '09 at 11:24
  • As toxvaerd points out, couldn't you use http://www.tug.org/utilities/texconv/rtf2latex2e.html ? – toolkit Feb 17 '09 at 11:49
  • http://sourceforge.net/projects/rtf2latex2e/ – toolkit Feb 17 '09 at 11:51

4 Answers4

6

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
  • 3,622
  • 3
  • 24
  • 29
1

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
  • 3,228
  • 3
  • 24
  • 20
0

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
  • 443
  • 1
  • 5
  • 17
0

Steer clear of LaTeX. Seriously.

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

cletus
  • 616,129
  • 168
  • 910
  • 942
  • 1
    That depends how much you care about typesetting... From the screenshots, it doesn't look like JEuclid care much about that aspect ;-) – toxvaerd Feb 17 '09 at 13:26