Convert MathML to MathType in MS Word
Asked Answered
A

4

6

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

Ator answered 9/6, 2009 at 11:8 Comment(0)
A
4

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.

Ator answered 12/6, 2009 at 19:13 Comment(1)
Could you please post complete vba Macros. I'm new in VBA and i would like to convert MathML2MathType OLE Format.Decidua
B
4

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.

Birck answered 10/6, 2009 at 14:16 Comment(2)
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!Ator
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 :)Ator
A
4

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.

Ator answered 12/6, 2009 at 19:13 Comment(1)
Could you please post complete vba Macros. I'm new in VBA and i would like to convert MathML2MathType OLE Format.Decidua
F
0

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.

Franconia answered 10/6, 2009 at 10:21 Comment(0)
C
0

Following simple procedure works:

  • Configure MathType to copy/paste preferences to: "Mathml" (suitable version to be chosen)
  • Paste your Mathml equation into Mathtype panel : the equation appears and can be edited/modified -> Fine adjust your equation.
  • Reconfigure copy/paste preferences of Mathtype to "Equation Object (Windows OLE Graphic)" -Copy paste now the equation from MathType to Word
Coextend answered 15/1, 2022 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.