Convert MathML to MathType in MS Word

stanch picture stanch · Jun 9, 2009 · Viewed 8.1k times · Source

I am writing a converter from XML&MathML to MS Word document.
I'm using MFC and Word automation, so there's no problem in writing text like this:

_Application app;  
COleVariant vtOpt(DISP_E_PARAMNOTFOUND, VT_ERROR),
            vtTrue((short)TRUE),
            vtFalse((short)FALSE);
app.CreateDispatch("Word.Application",NULL);
Documents docs = app.GetDocuments();
_Document doc = docs.Add (vtOpt, vtOpt, vtOpt, vtOpt);
Range range = doc.Range (vtOpt, vtOpt);
range.InsertAfter (_T("Hello Word!"));

Now the problem is in converting MathML equations into embedded MathType objects. One of the possible ways, that I've found, is to write equations in TeX and then programmatically call MTCommand_TeXToggle (found in MathType 6.5 library for Word) macro, that replaces TeX with MathType OLE objects. But then I have to convert MathML to TeX somehow, wich is not so easy.

I know, that MathType OLE object should accept raw MathML data, but when I'm trying to create and access OLE object programmatically:

InlineShapes shapes = doc.GetInlineShapes ();
InlineShape control = shapes.AddOLEObject (COleVariant("Equation.DSMT4"), vtOpt, vtFalse, vtFalse, vtOpt, vtOpt, vtOpt, vtOpt);
OLEFormat fm = control.GetOLEFormat ();
COleDispatchDriver drv = fm.GetObject();

I end up with no reasonable interface to feed it with the MathML data. So, the question is: 1) Is there a way to get control over the OLE object and send it some MathML data? Or 2) Is there a way to get a MS Word VB macro, that converts the selection from MathML to MathType OLE object?

Thanks in advance, Nick Stanch

Answer

Bob Mathews picture Bob Mathews · Jun 10, 2009

Nick, you should try our MathType SDK. It's offered "as-is", but it's free: http://www.dessci.com/en/reference/sdk/

Roel, thanks for the kind words. I'll pass this along to our Support team.

Bob Mathews Design Science

Update: Here's some clarification and additional information about my recommendation to try the MathType SDK. Starting with MathType 6.5, one can use the IDataObject interface on a MathType object to pass in MathML. The expression the MathML encodes is inserted at the current cursor location. Thus, in general, the strategy is to insert a blank MathType equation, activate it, get the IDataObject interface, set the equation via MathML, and then close the equation again.

The MathType SDK includes documentation with further detail, and a sample "OLECont" application demonstrating the technique. Based on what you've posted here, you should have no problem getting your code working.