Example #1
0
def latex2pixbuf(permeable,out_txt,latex_type):
    """
    Converting latex objects to RichTextImage
    """
    try:
        # Set the working directory
        workdir = tempfile.gettempdir()
        if latex_type== "InlineEquation":
            latex_name='formula.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=math2png(out_txt[1:-1], origfilename,permeable)
            if result_tag is -1:
                result_tag=error2png(origfilename)
            tag="3"
            tex=out_txt[1:-1].encode()
            caption=""
            label=""
        if latex_type== "Footnote":
            latex_name='footnote.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=footnote2png(origfilename)
            tag="8"
            tex=out_txt[10:-1].encode()
            caption=""
            label=""
        if latex_type== "LaTeX":
            latex_name='latex.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=latex2png(out_txt, origfilename,permeable)
            if result_tag is -1:
                result_tag=error2png(origfilename)
            tag="7"
            tex=out_txt.encode()
            caption=""
            label=""
        if latex_type== "Citation":
            latex_name='cite.png'
            origfilename=os.path.join(workdir,latex_name )
            result_tag=cite2png(out_txt[14:-1], origfilename,permeable)
            if result_tag is -1:
                result_tag=error2png(origfilename)
            tag="6"
            tex=out_txt[14:-1].encode()
            caption=""
            label=""
        if result_tag is not -1:
            img = RichTextImage()
            pixbuf=gdk.pixbuf_new_from_file(origfilename)
            pixbuf.save(origfilename,"png", {"tEXt::tag":tag,"tEXt::label":label,\
            "tEXt::caption":caption,"tEXt::tex":tex})
            img.set_from_pixbuf(gdk.pixbuf_new_from_file(origfilename.encode()))
            img.set_filename(latex_name)
        else:
            img=None
    finally:
        if os.path.exists(origfilename):
            os.remove(origfilename)


    return img
Example #2
0
def latex2pixbuf(permeable, out_txt, latex_type):
    """
    Converting latex objects to RichTextImage
    """
    try:
        # Set the working directory
        workdir = tempfile.gettempdir()
        if latex_type == "InlineEquation":
            latex_name = 'formula.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = math2png(out_txt[1:-1], origfilename, permeable)
            if result_tag is -1:
                result_tag = error2png(origfilename)
            tag = "3"
            tex = out_txt[1:-1].encode()
            caption = ""
            label = ""
        if latex_type == "Footnote":
            latex_name = 'footnote.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = footnote2png(origfilename)
            tag = "8"
            tex = out_txt[10:-1].encode()
            caption = ""
            label = ""
        if latex_type == "LaTeX":
            latex_name = 'latex.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = latex2png(out_txt, origfilename, permeable)
            if result_tag is -1:
                result_tag = error2png(origfilename)
            tag = "7"
            tex = out_txt.encode()
            caption = ""
            label = ""
        if latex_type == "Citation":
            latex_name = 'cite.png'
            origfilename = os.path.join(workdir, latex_name)
            result_tag = cite2png(out_txt[14:-1], origfilename, permeable)
            if result_tag is -1:
                result_tag = error2png(origfilename)
            tag = "6"
            tex = out_txt[14:-1].encode()
            caption = ""
            label = ""
        if result_tag is not -1:
            img = RichTextImage()
            pixbuf = gdk.pixbuf_new_from_file(origfilename)
            pixbuf.save(origfilename,"png", {"tEXt::tag":tag,"tEXt::label":label,\
            "tEXt::caption":caption,"tEXt::tex":tex})
            img.set_from_pixbuf(gdk.pixbuf_new_from_file(
                origfilename.encode()))
            img.set_filename(latex_name)
        else:
            img = None
    finally:
        if os.path.exists(origfilename):
            os.remove(origfilename)

    return img
Example #3
0
 def execute_code(self, tex):
     latex_permeable=_load_permeable(self.main_window._page)
     if self._TAG == "3":
         tag=math2png(tex, self._image_path, latex_permeable)
         if tag is -1:
             tag=error2png(self._image_path)
     elif self._TAG == "4":
         tag=eqn2png(tex, self._image_path, latex_permeable)
         if tag is -1:
             tag=error2png(self._image_path)
     elif self._TAG == "5":
         tag=table2png(tex, self._image_path, latex_permeable)
         if tag is -1:
             tag=error2png(self._image_path)
     elif self._TAG == "6":
         tag=cite2png(tex, self._image_path, latex_permeable)
         if tag is -1:
             tag=error2png(self._image_path)
     elif self._TAG == "7":
         tag=latex2png(tex, self._image_path, latex_permeable)
         if tag is -1:
             tag=error2png(self._image_path)