Convert MathML to MathType in MS Word

I am writing a converter from XML & MathML to an MS Word document.
I use MFC and Word automation, so there is no problem writing text as follows:

_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 transforming the MathML equations into built-in MathType objects. One possible way that I found was to write equations in TeX, and then programmatically call MTCommand_TeXToggle (found in the MathType 6.5 library for Word) a macro that replaces TeX with MathType OLE objects. But then I have to convert MathML to TeX or otherwise, which is not so simple.

I know that a MathType OLE object must accept raw MathML data, but when I try to create and OLE access to objects 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(); 

In the end, I don’t have a reasonable interface to feed it with MathML data. So the question is: 1) Is there a way to take control of an OLE object and send it some MathML data? Or 2) Is there a way to get an MS Word VB macro that converts a selection from MathML to MathType of an OLE object?

Thanks in advance, Nick Stanch

+4
source share
3 answers

Cracked him!

You can use the COleClientItem object to get an MATType OLE Control instance in its code. This is shown in the MATType SDK MFC. Then, manipulating COleDataSource , take control of the MathML data and call COleClientItem::CopyToClipboard(); Now the data representing the control itself as an OLE object is available when calling Range::Paste(opt1, opt2); from Word Automation classes. It looks a bit strange, but it worked for me :) And all you have to do is add another line to the sample, namely the one that calls the CopyToClipboard method.

+2
source

Nick, you should try our MathType SDK. He offered "as is", but he is free: http://www.dessci.com/en/reference/sdk/

Roel, thanks for the kind words. I will forward this to our support team.

Bob Matthews Design Science

Update: Here are some explanations and additional information about my recommendation to try the MathType SDK. Starting with MathType 6.5, you can use the IDataObject interface for a MathType object to pass to MathML. An expression of MathML encodings is inserted at the current cursor location. Thus, the overall strategy is to insert an empty MathType equation, activate it, get the IDataObject interface, set the equation through MathML, and then close the equation again.

The MathType SDK includes detailed documentation with documentation and an example OLECont application demonstrating this technique. Based on what you posted here, you should have no problems with your code.

+3
source

The only advice I can offer is that I always found support in the field of design, which was not bad. You can ask them if their OLE interface supports MathML.

I have not yet explored the Word 2007 equation editor. It may be easier to import other formats if it has a different automation interface.

0
source

Source: https://habr.com/ru/post/1285953/


All Articles