Skip to content

Instantly share code, notes, and snippets.

@zourtney
Created February 2, 2012 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zourtney/1726138 to your computer and use it in GitHub Desktop.
Save zourtney/1726138 to your computer and use it in GitHub Desktop.
MathType clipboard-to-clipboard transformation works on Windows, fails on OSX
# NOTE: Python must be invoked in 32-bit mode for ctypes to read the MathType lib.
# For example (OSX):
# arch -i386 /usr/bin/python2.6 mathtype_mathml.py
#
import sys
from ctypes import *
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) # mtinitLAUNCH_AS_NEEDED
# Use MathML translation mode
file = "MathML2 (namespace attr).tdl".encode('utf-8')
lib.MTXFormSetTranslator(4, file) # mtxfmTRANSL_INC_MTDEFAULT
# Set source and destination as clipboard
src = -2 # mtxfmCLIPBOARD
src_format = 7 # mtxfmTEXT
dst = -2 # mtxfmCLIPBOARD
dst_format = 7 # mtxfmTEXT
# Convert (get MathML)
result = lib.MTXFormEqn(src, src_format, None, 0,
dst, dst_format, None, 0,
'', None)
return 0
if __name__ == "__main__":
sys.exit(main())
# The following code will print the available pasteboard types. If a MathType
# equation is on the clipboard, you will see 'pict' available. This is what
# I get:
# (
# "dyn.ah62d4rv4gk8ynynsku",
# "CorePasteboardFlavorType 0x45514E44",
# "dyn.ah62d4rv4gk8y4xnqna",
# "CorePasteboardFlavorType 0x4D4D4C50",
# "com.adobe.pdf",
# "Apple PDF pasteboard type",
# "com.apple.pict",
# "Apple PICT pasteboard type",
# "dyn.ah62d4rv4gk8y4zcrna",
# "CorePasteboardFlavorType 0x4D544D50"
#)
#
from AppKit import NSPasteboard
pb = NSPasteboard.generalPasteboard()
print pb.types()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment