Example #1
0
    def owriteMath(self, obj): 
        """
        get a MATHML from Latex
        translate element tree to odf.Elements
        """
        #log("math")
        r = writerbase.renderMath(obj.caption, output_mode='mathml', render_engine='blahtexml')        
        if not r:
            log("writerbase.renderMath failed!")
            return
        #print mathml.ET.tostring(r)
        
        def _withETElement(e, parent):
            # translate to odf.Elements
            for c in e.getchildren():
                n = math.Element(qname=(math.MATHNS, str(c.tag)))
                parent.addElement(n)
                if c.text:
                    text = c.text
                    #if not isinstance(text, unicode):  text = text.decode("utf8")
                    n.appendChild(odf.element.Text(text)) # n.addText(c.text)
                    # rffixme: odfpy0.8 errors:"AttributeError: Element instance has no attribute 'elements'" -> this is a lie!
                _withETElement(c, n)

        mathframe = draw.Frame(stylename=style.formula, zindex=0, anchortype="as-char") 
        mathobject = draw.Object() 
        mathframe.addElement(mathobject)
        mroot = math.Math()
        mathobject.addElement(mroot)
        _withETElement(r, mroot)
        return mathframe
Example #2
0
    def xwriteMath_WITH_OBJECT(self, obj):
        """
        this won't validate as long as we are using xhtml 1.0 transitional

        see also: http://www.mozilla.org/projects/mathml/authoring.html
        """
        s = ET.Element("object")
        s.set("class", "mwx-math")
        s.set("type", "application/x-latex")
        s.set("src", "data:text/plain;charset=utf-8,%s" % obj.caption)
        r = writerbase.renderMath(obj.caption, output_mode='mathml', render_engine='blahtexml')
        if not r:
            #r = ET.Element("em")
            #r.set("class", "math.error")
            #r.text = obj.caption
            pass
        else:
            assert r is not None
            s.append(r)
        return s
Example #3
0
    def dbwriteMath(self, obj): 
        r = writerbase.renderMath(obj.caption, output_mode='mathml', render_engine='blahtexml')        
        if not r:
            r = Element("phrase", role="texmath")
            r.text = obj.caption
            return r

        def _withETElement(e, parent):
            # translate to lxml.Elements
            for c in e.getchildren():
                #n = math.Element(qname=(math.MATHNS, str(c.tag)))
                n = Element(str(c.tag))
                parent.append(n)
                if c.text:
                    n.text = c.text
                _withETElement(c, n)

        m = Element("math", xmlns="http://www.w3.org/1998/Math/MathML")
        _withETElement(r,m)
        return m
    def dbwriteMath(self, obj): 
        r = writerbase.renderMath(obj.caption, output_mode='mathml', render_engine='blahtexml')        
        if not r:
            r = Element("phrase", role="texmath")
            r.text = obj.caption
            return r

        def _withETElement(e, parent):
            # translate to lxml.Elements
            for c in e.getchildren():
                #n = math.Element(qname=(math.MATHNS, str(c.tag)))
                n = Element(str(c.tag))
                parent.append(n)
                if c.text:
                    n.text = c.text
                _withETElement(c, n)

        m = Element("math", xmlns="http://www.w3.org/1998/Math/MathML")
        _withETElement(r,m)
        return m
Example #5
0
    def xwriteMath_WITH_OBJECT(self, obj):
        """
        this won't validate as long as we are using xhtml 1.0 transitional

        see also: http://www.mozilla.org/projects/mathml/authoring.html
        """
        s = ET.Element("object")
        s.set("class", "mwx.math")
        s.set("type", "application/x-latex")
        s.set("src", "data:text/plain;charset=utf-8,%s" % obj.caption)
        r = writerbase.renderMath(obj.caption,
                                  output_mode='mathml',
                                  render_engine='blahtexml')
        if not r:
            #r = ET.Element("em")
            #r.set("class", "math.error")
            #r.text = obj.caption
            pass
        else:
            assert r is not None
            s.append(r)
        return s
Example #6
0
 def xwriteMath(self, obj):
     return writerbase.renderMath(obj.caption, output_mode='mathml', render_engine='blahtexml')
Example #7
0
 def xwriteMath(self, obj):
     return writerbase.renderMath(obj.caption,
                                  output_mode='mathml',
                                  render_engine='blahtexml')