I am using the MathType SDK from Python to get MathML from MathType objects. In Windows, MTXFormEqn()
can replace MathType OLE object on the clipboard with its transformed equivalent. This seems to be the standard approach.
lib.MTXFormSetTranslator(4, TRANSLATOR_TDL_FILENAME)
lib.MTXFormEqn(mtxfmCLIPBOARD, mtxfmTEXT, None, 0, # source
mtxfmCLIPBOARD, mtxfmTEXT, None, 0, # dest
'', None)
I am attempting to port this to OSX, but I can't figure out what data to pass into MTXFormEqn()
. Calling the code above simple returns mtOK
and MTXFormGetStatus()
reports a generic error.
This chart suggests the source must be 'file' instead. The documentation lists "PICT" as a possible input format. MTEquationOnClipboard()
reports a MathType clipboard object as type WMF (2
), but I can get its PICT
equivalent using NSPasteboard
.
pb = NSPasteboard.generalPasteboard()
data = pb.dataForType_(NSPICTPboardType)
Has anyone successfully used MTXFormEqn()
to translate MathType objects on the Mac? I can't find any examples (in the documentation or online) which use anything expect the standard clipboard-to-clipboard method from Windows.
Here is a stripped down version of the working Windows code. Error checking and const definitions omitted for brevity.
import sys
from ctypes import *
TRANSLATOR_TDL = 'MathML2 (namespace attr).tdl'
def main():
# On OSX, use the following line instead:
# lib = cdll.LoadLibrary('/Library/Frameworks/MT6Lib.framework/MT6Lib')
lib = windll.LoadLibrary('MT6.dll')
lib.MTAPIConnect(0, 30)
lib.MTXFormSetTranslator(4, TRANSLATOR_TDL)
eq_type = lib.MTEquationOnClipboard()
if eq_type == 8: # mtOLE2_EQUATION -- Windows only
lib.MTXFormEqn(mtxfmCLIPBOARD, mtxfmTEXT, None, 0, # source
mtxfmCLIPBOARD, mtxfmTEXT, None, 0, # dest
'', None)
#
# MathML contents now on clipboard as string
#
elif eq_type == 2: # mtWMF_EQUATION -- Mac OSX
???
return 0
if __name__ == "__main__":
sys.exit(main())
If there is MathType equation data on the clipboard (of any type) then
should work on either platform (Mac or Win). How are you getting the MT eqn data on to the clipboard? Do you have a way to tell What is actually on the clipboard when you call MTXFormEqn?