(string, inline=True)
return tree
parse_latex_math(string [,inline]) -> MathML-tree

    Returns a MathML-tree parsed from string.  inline=True is for
    inline math and inline=False is for displayed math.

    tree is the whole tree and node is the current element.
parse_latex_math(string [,inline]) -> MathML-tree
parse_latex_math ( string [ inline ] ) - > MathML - tree
def parse_latex_math(string, inline=True):
    """parse_latex_math(string [,inline]) -> MathML-tree

    Returns a MathML-tree parsed from string.  inline=True is for
    inline math and inline=False is for displayed math.

    tree is the whole tree and node is the current element."""

    # Normalize white-space:
    string = ' '.join(string.split())

    if inline:
        node = mrow()
        tree = math(node, inline=True)
    else:
        node = mtd()
        tree = math(mtable(mtr(node)), inline=False)

    while len(string) > 0:
        n = len(string)
        c = string[0]
        skip = 1  # number of characters consumed
        if n > 1:
            c2 = string[1]
        else:
            c2 = ''
##        print n, string, c, c2, node.__class__.__name__
        if c == ' ':
            pass
        elif c == '\\':
            if c2 in '{}':
                node = node.append(mo(c2))
                skip = 2
            elif c2 == ' ':
                node = node.append(mspace())
                skip = 2
            elif c2.isalpha():
                # We have a LaTeX-name:
                i = 2
                while i < n and string[i].isalpha():
                    i += 1
                name = string[1:i]
                node, skip = handle_keyword(name, node, string[i:])
                skip += i
            elif c2 == '\\':
                # End of a row:
                entry = mtd()
                row = mtr(entry)
                node.close().close().append(row)
                node = entry
                skip = 2
            else:
                raise SyntaxError('Syntax error: "%s%s"' % (c, c2))
        elif c.isalpha():
            node = node.append(mi(c))
        elif c.isdigit():
            node = node.append(mn(c))
        elif c in "+-/()[]|=<>,.!'":
            node = node.append(mo(c))
        elif c == '_':
            child = node.delete_child()
            if isinstance(child, msup):
                sub = msubsup(child.children, reversed=True)
            elif isinstance(child, mo) and child.data in sumintprod:
                sub = munder(child)
            else:
                sub = msub(child)
            node.append(sub)
            node = sub
        elif c == '^':
            child = node.delete_child()
            if isinstance(child, msub):
                sup = msubsup(child.children)
            elif isinstance(child, mo) and child.data in sumintprod:
                sup = mover(child)
            elif (isinstance(child, munder) and
                  child.children[0].data in sumintprod):
                sup = munderover(child.children)
            else:
                sup = msup(child)
            node.append(sup)
            node = sup
        elif c == '{':
            row = mrow()
            node.append(row)
            node = row
        elif c == '}':
            node = node.close()
        elif c == '&':
            entry = mtd()
            node.close().append(entry)
            node = entry
        else:
            raise SyntaxError('Illegal character: "%s"' % c)
        string = string[skip:]
    return tree
def parse_latex_math ( string , inline = True ) : # Normalize white-space: string = ' ' . join ( string . split ( ) ) if inline : node = mrow ( ) tree = math ( node , inline = True ) else : node = mtd ( ) tree = math ( mtable ( mtr ( node ) ) , inline = False ) while len ( string ) > 0 : n = len ( string ) c = string [ 0 ] skip = 1 # number of characters consumed if n > 1 : c2 = string [ 1 ] else : c2 = '' ##        print n, string, c, c2, node.__class__.__name__ if c == ' ' : pass elif c == '\\' : if c2 in '{}' : node = node . append ( mo ( c2 ) ) skip = 2 elif c2 == ' ' : node = node . append ( mspace ( ) ) skip = 2 elif c2 . isalpha ( ) : # We have a LaTeX-name: i = 2 while i < n and string [ i ] . isalpha ( ) : i += 1 name = string [ 1 : i ] node , skip = handle_keyword ( name , node , string [ i : ] ) skip += i elif c2 == '\\' : # End of a row: entry = mtd ( ) row = mtr ( entry ) node . close ( ) . close ( ) . append ( row ) node = entry skip = 2 else : raise SyntaxError ( 'Syntax error: "%s%s"' % ( c , c2 ) ) elif c . isalpha ( ) : node = node . append ( mi ( c ) ) elif c . isdigit ( ) : node = node . append ( mn ( c ) ) elif c in "+-/()[]|=<>,.!'" : node = node . append ( mo ( c ) ) elif c == '_' : child = node . delete_child ( ) if isinstance ( child , msup ) : sub = msubsup ( child . children , reversed = True ) elif isinstance ( child , mo ) and child . data in sumintprod : sub = munder ( child ) else : sub = msub ( child ) node . append ( sub ) node = sub elif c == '^' : child = node . delete_child ( ) if isinstance ( child , msub ) : sup = msubsup ( child . children ) elif isinstance ( child , mo ) and child . data in sumintprod : sup = mover ( child ) elif ( isinstance ( child , munder ) and child . children [ 0 ] . data in sumintprod ) : sup = munderover ( child . children ) else : sup = msup ( child ) node . append ( sup ) node = sup elif c == '{' : row = mrow ( ) node . append ( row ) node = row elif c == '}' : node = node . close ( ) elif c == '&' : entry = mtd ( ) node . close ( ) . append ( entry ) node = entry else : raise SyntaxError ( 'Illegal character: "%s"' % c ) string = string [ skip : ] return tree