def getMathMl(oleFormat, runForConversion=True): """Get MathML from a MathType OLEFormat object. """ if runForConversion: oleFormat.DoVerb(2) # "RunForConversion" mt = oleFormat.object._comobj length = ctypes.c_long() # 2 is get MathML try: if lib.MTGetLangStrFromEqn(mt, 2, None, ctypes.byref(length)) != 0: raise RuntimeError mathMl = (ctypes.c_char * length.value)() if lib.MTGetLangStrFromEqn(mt, 2, ctypes.byref(mathMl), ctypes.byref(length)) != 0: raise RuntimeError finally: # 1 is OLECLOSE_NOSAVE lib.MTCloseOleObject(1, mt) return mathPres.stripExtraneousXml(mathMl.value)
def _get_mathMl(self): import mathPres mathMl = mathPres.stripExtraneousXml(self.HTMLNode.outerHTML) if not mathPres.getLanguageFromMath(mathMl) and self.language: mathMl = mathPres.insertLanguageIntoMath(mathMl, self.language) return mathMl