コード例 #1
0
def print_gtk(x, start_viewer=True):
    """Print to Gtkmathview, a gtk widget capable of rendering MathML.

    Needs libgtkmathview-bin"""
    with tempfile.NamedTemporaryFile('w') as file:
        file.write(c2p(mathml(x), simple=True))
        file.flush()

        if start_viewer:
            subprocess.check_call(('mathmlviewer', file.name))
コード例 #2
0
 def add_math(self, parent, expr):
     if self.add_mathml:
         ml = printing.mathml(expr)
         pm = c2p(ml, add_header=True)
         tree = minidom.parseString(pm)
         self.add_math_node(parent, tree.firstChild)
     else:
         #lt = latex(expr,mode="inline")
         lt = latex(expr, mode="equation", itex=True)
         self.create_child_text_element(parent, "div", lt)
コード例 #3
0
 def add_math(self, parent, expr):
     if self.add_mathml:
         ml = printing.mathml(expr)
         pm = c2p(ml, add_header=True)
         tree = minidom.parseString(pm)
         self.add_math_node(parent, tree.firstChild)
     else:
         #lt = latex(expr,mode="inline")
         lt = latex(expr,mode="equation",itex=True)
         self.create_child_text_element(parent, "div", lt)
コード例 #4
0
ファイル: gtk.py プロジェクト: certik/sympy-oldcore
def print_gtk(x):
    """Print to Gtkmathview, a gtk widget capable of rendering MathML.
    Needs libgtkmathview-bin"""
    from sympy.utilities.mathml import c2p

    tmp = tempfile.mktemp() # create a temp file to store the result
    file = open(tmp, 'wb')
    file.write( c2p(mathml(x), simple=True) )
    file.close()

    os.system("mathmlviewer " + tmp)
コード例 #5
0
ファイル: gtk.py プロジェクト: Visheshk/sympy
def print_gtk(x, start_viewer=True):
    """Print to Gtkmathview, a gtk widget capable of rendering MathML.
    Needs libgtkmathview-bin"""
    from sympy.utilities.mathml import c2p

    tmp = tempfile.mktemp() # create a temp file to store the result
    with open(tmp, 'wb') as file:
        file.write( c2p(mathml(x), simple=True) )

    if start_viewer:
        os.system("mathmlviewer " + tmp)
コード例 #6
0
ファイル: gtk.py プロジェクト: asmeurer/sympy
def print_gtk(x, start_viewer=True):
    """Print to Gtkmathview, a gtk widget capable of rendering MathML.

    Needs libgtkmathview-bin
    """
    from sympy.utilities.mathml import c2p

    tmp = tempfile.mkstemp()  # create a temp file to store the result
    with open(tmp, 'wb') as file:
        file.write(c2p(mathml(x), simple=True))

    if start_viewer:
        os.system("mathmlviewer " + tmp)
コード例 #7
0
ファイル: SimplifyEquations.py プロジェクト: biswajitsc/LaSer
def main():
    in_file = open(sys.argv[1], "r")
    in_meta_file = open(sys.argv[2], "r")
    out_file = open("../../Data/Expressions", "w")
    output_file = open("../../Data/SimplifiedMathML.xml", "w")
    out_meta_file = open("../../Data/SimplifiedMathMLMeta.xml", "w")
    data = in_file.read()
    metadata = in_meta_file.read()
    mathml_eqns = data.split("\n")
    metadata_eqns = metadata.split("\n")
    print len(mathml_eqns), len(metadata_eqns)
    i = 0
    j = 0
    for mathml_eqn in mathml_eqns:
        j += 1
        # if (str(mathml_eqn) == '<?xml version="1.0" encoding="UTF-8"?>' or len(mathml_eqn) == 0) :
        # 	continue
        mathml_eqn = mathml_eqn.replace("\n", " ")
        temp_mathml_eqn = mathml_eqn
        if i % 100 == 0:
            print i, "done"
        try:
            mathml_eqn = mathml_eqn.replace("<m:mo><U+2062></m:mo>", "")
            (expr, symbvars) = parseMML(mathml_eqn)
            # print "Expr : ", expr
            simp_expr = sympy.simplify(expr)
            out_file.write(str(expr) + "\n$$\n$$\n" + str(simp_expr) + "\n")
            c_mathml = sympy.printing.mathml(simp_expr)
            from sympy.utilities.mathml import c2p

            p_mathml = c2p(c_mathml)
            p_mathml = str(p_mathml)
            p_mathml = p_mathml.replace("\n", " ")
            output_file.write(str(temp_mathml_eqn) + "\n" + p_mathml + "\n")
            out_meta_file.write(
                str(metadata_eqns[i]) + " " + str(j) + "\n" + str(metadata_eqns[i]) + " " + str(j) + "\n"
            )
        except Exception as e:
            # print e
            # print mathml_eqn
            output_file.write(str(temp_mathml_eqn) + "\n")
            out_meta_file.write(str(metadata_eqns[i]) + " " + str(j) + "\n")
        i += 1

    in_file.close()
    out_file.close()