elsie/box.py
def latex(self, text, scale=1.0, header=None, tail=None):
        """ Renders LaTeX text into box. """

        if header is None:
            header = """
\\documentclass[varwidth,border=1pt]{standalone}
\\usepackage[utf8x]{inputenc}
\\usepackage{ucs}
\\usepackage{amsmath}
\\usepackage{amsfonts}
\\usepackage{amssymb}
\\usepackage{graphicx}
\\begin{document}"""

        if tail is None:
            tail = "\\end{document}"

        tex_text = "\n".join((header, text, tail))

        container = [None, None, None]

        def on_query(svg):
            root = et.fromstring(svg)
            svg_width = svg_size_to_pixels(root.get("width")) * scale
            svg_height = svg_size_to_pixels(root.get("height")) * scale

            self._ensure_width(svg_width)
            self._ensure_height(svg_height)

            container[0] = svg_width
            container[1] = svg_height
            container[2] = svg

        def draw(ctx, rect):
            svg_width, svg_height, data = container
            x = rect.x + (rect.width - svg_width) / 2
            y = rect.y + (rect.height - svg_height) / 2
            self._render_svg(ctx, x, y, scale, data)

        self._queries.append(Query(("latex", tex_text), on_query))
        self.add_child(draw)
 Renders LaTeX text into box. 
Renders LaTeX text into box.
Renders LaTeX text into box .
def latex(self, text, scale=1.0, header=None, tail=None):
        if header is None:
            header = """
\\documentclass[varwidth,border=1pt]{standalone}
\\usepackage[utf8x]{inputenc}
\\usepackage{ucs}
\\usepackage{amsmath}
\\usepackage{amsfonts}
\\usepackage{amssymb}
\\usepackage{graphicx}
\\begin{document}"""
        if tail is None:
            tail = "\\end{document}"
        tex_text = "\n".join((header, text, tail))
        container = [None, None, None]
        def on_query(svg):
            root = et.fromstring(svg)
            svg_width = svg_size_to_pixels(root.get("width")) * scale
            svg_height = svg_size_to_pixels(root.get("height")) * scale
            self._ensure_width(svg_width)
            self._ensure_height(svg_height)
            container[0] = svg_width
            container[1] = svg_height
            container[2] = svg
        def draw(ctx, rect):
            svg_width, svg_height, data = container
            x = rect.x + (rect.width - svg_width) / 2
            y = rect.y + (rect.height - svg_height) / 2
            self._render_svg(ctx, x, y, scale, data)
        self._queries.append(Query(("latex", tex_text), on_query))
        self.add_child(draw)
def latex ( self , text , scale = 1.0 , header = None , tail = None ) : if header is None : header = """
\\documentclass[varwidth,border=1pt]{standalone}
\\usepackage[utf8x]{inputenc}
\\usepackage{ucs}
\\usepackage{amsmath}
\\usepackage{amsfonts}
\\usepackage{amssymb}
\\usepackage{graphicx}
\\begin{document}""" if tail is None : tail = "\\end{document}" tex_text = "\n" . join ( ( header , text , tail ) ) container = [ None , None , None ] def on_query ( svg ) : root = et . fromstring ( svg ) svg_width = svg_size_to_pixels ( root . get ( "width" ) ) * scale svg_height = svg_size_to_pixels ( root . get ( "height" ) ) * scale self . _ensure_width ( svg_width ) self . _ensure_height ( svg_height ) container [ 0 ] = svg_width container [ 1 ] = svg_height container [ 2 ] = svg def draw ( ctx , rect ) : svg_width , svg_height , data = container x = rect . x + ( rect . width - svg_width ) / 2 y = rect . y + ( rect . height - svg_height ) / 2 self . _render_svg ( ctx , x , y , scale , data ) self . _queries . append ( Query ( ( "latex" , tex_text ) , on_query ) ) self . add_child ( draw )
Renders LaTeX text into box.
Renders LaTeX text into box .
""" Renders LaTeX text into box. """
self
text
scale
header
tail