views:

420

answers:

5

Are there any libraries which take MathML (or, even more preferably, OMML) and outputs a .PNG file?

I am putting together an export process for .docx files and, as a part of this process, I'd like to extract equations and render them as .PNG files. Word 2007 does this natively when you save a document for the web, but so far, I have not been able to find a way to do this programmatically (if anyone has an answer for that, it would be even better). So the next best thing is to take the OMML and use the Microsoft provided XSL stylesheets and transform them to MathML.

Unfortunately, I haven't been able to find any (working) rendering libraries for either MathML or OMML.

If there aren't any pure .NET libraries for this, I'll settle for just about anything that I can call from a commandline to output a .PNG from either MathML or OMML.

+1  A: 

You can try SVGMath to convert mathml to SVG and then some tool to convert svg to png e.g.

http://harriyott.com/2008/05/converting-svg-images-to-png-in-c.aspx

or user rsvg lib to convert svg to png files.

Anurag Uniyal
A: 

You can try Java library JEuclid: http://jeuclid.sourceforge.net/

Sutra
A: 

Some okay news, some not so great news and some weird news:

The okay news is the library you're looking for is at http://msdn.microsoft.com/en-us/library/documentformat.openxml.math%28office.14%29.aspx. At least that's what I think you're looking for.

The not so great news is that the code below doesn't exactly work as hoped - it copies most of the characters as "?" and the resulting image is pretty much crap.

Sub SaveOMML()
Dim rng As Range
Dim Equation As OMath

Set rng = Selection.Range
rng.Text = "Celsius = (5/9)(Fahrenheit – 32)"
Set rng = Selection.OMaths.Add(rng)
Set Equation = rng.OMaths(1)
Equation.BuildUp
Equation.Range.Select

With Selection.Range
        .CopyAsPicture
        .PasteSpecial DataType:=wdPasteMetafilePicture
End With

End Sub

The weird news is that OMML does copy/paste into PowerPoint just fine as an image, which can then be saved out as a PNG. At little cumbersome, but it can be done with VSTO.

Otaku
Copy/Paste may not work well, but save as produces nice results for me
Scott Weinstein
A: 

We make a DLL library called the Equation Composer that many use with .NET to convert MathML to PNG. It's also available as a commandline executable. It's not free, but that means you get technical support and bug fixes. More info is available here: http://dessci.com/en/products/mathflow/mf_components.htm

Autumn Cuellar
A: 

I have a similar need. Here's a fragment that works for me:

public void FormulaToImage(string imageName, string eq)
{
    Application app = new Application();
    Document _doc = app.Documents.Add();
    Range _range = _doc.Range();
    _range.Text = eq; // "Celsius = (5/9)(Fahrenheit – 32)";
    _doc.OMaths.Add(_range);
    _doc.OMaths.BuildUp();
    _doc.SaveAs(@"foo.htm", WdSaveFormat.wdFormatHTML);

    //the gif appears to be better quality than the png
    File.Move(@"foo_files\image002.gif", imageName + ".gif");                
    app.Documents.Close(WdSaveOptions.wdDoNotSaveChanges);
    app.Quit(false);
}
Scott Weinstein