Algorithm or code for converting OMML to MathML

5.5k Views Asked by At

I am in the process of converting Word doc standard equations (OMML) to MathML using flash or Flex, please help me out by providing simple Algorithm or code snippet.

Thanks in advance, Mani

2

There are 2 best solutions below

3
David Carlisle On

There is an XSLT 1 stylesheet that does that conversion provided by microsoft as part of the Word Distribution, it is what handles placing MathML on the clipboard in Word. Typically installed as something like

c:/Program Files (x86)/Microsoft Office/Office14/OMML2MML.XSL

There is some discussion of an early version of this at

http://dpcarlisle.blogspot.co.uk/2007/04/xhtml-and-mathml-from-office-20007.html

0
Romany-Saad On

here is snippet of a C# class I was working on a few days ago ... I know it's too late .. but for less future pain.

I think it's not very different in Action Script

the file OMML2MML.xsl is located at %ProgramFiles%\Microsoft Office\Office12\ as mentioned by @David the xsl file is used for placing MathML on the clipboard in Word and converting OMML to MML too.

public static string OMML(string omml)
{
    XslCompiledTransform xslTransform = new XslCompiledTransform();
    xslTransform.Load("OMML2MML.xsl");

    using (XmlReader reader = XmlReader.Create(new StringReader(omml)))
    {
        using (MemoryStream ms = new MemoryStream())
        {
            XmlWriterSettings settings = xslTransform.OutputSettings.Clone();

            // Configure xml writer to omit xml declaration.
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.OmitXmlDeclaration = true;

            XmlWriter xw = XmlWriter.Create(ms, settings);

            // Transform our OfficeMathML to MathML
            xslTransform.Transform(reader, xw);
            ms.Seek(0, SeekOrigin.Begin);

            StreamReader sr = new StreamReader(ms, Encoding.UTF8);
            string MathML = sr.ReadToEnd();
            return MathML;
        }
    }
}