views:

1273

answers:

4

Hi,
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

A: 

The only advice I can offer is that I've always found the Design Science support to be quite good. You may want to ask them whether their OLE interface offers MathML support.

I haven't investigated the Word 2007 equation editor yet. Maybe it can import other formats more easily, if it has a different automation interface.

Roel
+3  A: 

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.

Thanks for your answer. Actually, I had the SDK at that moment, but i was writing in C++, not C#, so i failed to figure out how to implement the IDataObject thing. So, instead of that, i've used your MFC sample. It goes like this: I get COleClientItem from clsid, feed it with mathml and then call CopyToClipboard, simply pasting it somewhere in the document. Looks like a bit weird, I know. Still, it worked perfect for me. And I get a free mathml->TeX converter! Thanks for you great products!
stanch
Well, now I remember that OLECont is exactly the thing I've told You about. So seems like I had anticipated your advice two days day before yesterday :)
stanch
Glad it's working for you. Thanks for the update. -- Bob
A: 

Cracked it!

One can use COleClientItem object to obtain an instance of MathType OLE Control in his code. That is shown in the MathType SDK MFC sample. Then, manipulating the COleDataSource, feed the control with MathML data and call COleClientItem::CopyToClipboard(); Now the data, representing the control itself, as an OLE object, is available upon Range::Paste(opt1, opt2); call from Word automation classes. Looks a bit weird, but worked for me :) And all you have to do is add one more line to the sample, namely the one that calls CopyToClipboard method.

stanch
A: 

I tried Bob Mathews solution for importing MathML. Inserting a blank MathType equation results in MathType window to flash(appear and disappear). Is there any way to get rid of that issue?

Abhishek