From: Andy R. Terrel <[EMAIL PROTECTED]> --- examples/all.py | 2 +- examples/intermediate/print_gtk.py | 11 +++---- sympy/printing/mathml.py | 48 +++++++++++++++++++--------------- sympy/printing/tests/test_mathml.py | 18 ++++++++---- 4 files changed, 45 insertions(+), 34 deletions(-)
diff --git a/examples/all.py b/examples/all.py index 3a395ab..0b6f9f1 100755 --- a/examples/all.py +++ b/examples/all.py @@ -66,7 +66,7 @@ TERMINAL_EXAMPLES = [ WINDOWED_EXAMPLES = [ "beginner.plotting_nice_plot", - #"intermediate.print_gtk", + "intermediate.print_gtk", "intermediate.mplot2d", "intermediate.mplot3d", "advanced.plotting", diff --git a/examples/intermediate/print_gtk.py b/examples/intermediate/print_gtk.py index aca5ff9..9d07fb0 100755 --- a/examples/intermediate/print_gtk.py +++ b/examples/intermediate/print_gtk.py @@ -4,17 +4,16 @@ Demonstrates printing with gtkmathview using mathml """ -from sympy import Symbol, integrate, exp -from sympy.printing import print_gtk +from sympy import Integral, Limit, print_gtk, sin, Symbol def main(): x = Symbol('x') - #l1 = limit(sin(x)/x, x, 0, evaluate=False) - #print_gtk(l1) + example_limit = Limit(sin(x)/x, x, 0) + print_gtk(example_limit) - l2 = integrate(exp(x), (x,0,1), evaluate=False) - print_gtk(l2) + example_integral = Integral(x, (x, 0, 1)) + print_gtk(example_integral) if __name__ == "__main__": main() diff --git a/sympy/printing/mathml.py b/sympy/printing/mathml.py index 1629786..ec6c88c 100644 --- a/sympy/printing/mathml.py +++ b/sympy/printing/mathml.py @@ -52,34 +52,40 @@ class MathMLPrinter(Printer): x_1 = self.dom.createElement('bvar') x_2 = self.dom.createElement('lowlimit') - x_1.appendChild(self._print(e.x)) - x_2.appendChild(self._print(e.x0)) + x_1.appendChild(self._print(e.args[1])) + x_2.appendChild(self._print(e.args[2])) x.appendChild(x_1) x.appendChild(x_2) - x.appendChild(self._print(e.e)) + x.appendChild(self._print(e.args[0])) return x - def _print_Integral(self, e): - # FIXME doesn't work -- needs to be updated to the new Integral class - x = self.dom.createElement('apply') - x.appendChild(self.dom.createElement(self.mathml_tag(e))) - - x_1 = self.dom.createElement('bvar') - x_2 = self.dom.createElement('lowlimit') - x_3 = self.dom.createElement('uplimit') - #x_1.appendChild(self._print(e.x)) - #x_2.appendChild(self._print(e.a)) - #x_3.appendChild(self._print(e.b)) - - x.appendChild(x_1) - x.appendChild(x_2) - x.appendChild(x_3) - x.appendChild(self._print(e.f)) - - return x + def _print_Integral(self, e): + def lime_recur(limits): + x = self.dom.createElement('apply') + x.appendChild(self.dom.createElement(self.mathml_tag(e))) + bvar_elem = self.dom.createElement('bvar') + bvar_elem.appendChild(self._print(limits[0][0])) + x.appendChild(bvar_elem) + + if limits[0][1]: + low_elem = self.dom.createElement('lowlimit') + low_elem.appendChild(self._print(limits[0][1][0])) + x.appendChild(low_elem) + up_elem = self.dom.createElement('uplimit') + up_elem.appendChild(self._print(limits[0][1][1])) + x.appendChild(up_elem) + if len(limits) == 1: + x.appendChild(self._print(e.function)) + else: + x.appendChild(lime_recur(limits[1:])) + return x + + limits = list(e.limits) + limits.reverse() + return lime_recur(limits) def _print_Symbol(self, sym): x = self.dom.createElement(self.mathml_tag(sym)) diff --git a/sympy/printing/tests/test_mathml.py b/sympy/printing/tests/test_mathml.py index 7b5955a..6d7f55c 100644 --- a/sympy/printing/tests/test_mathml.py +++ b/sympy/printing/tests/test_mathml.py @@ -1,7 +1,6 @@ -from sympy import Symbol, sin, diff +from sympy import diff, Integral, Limit, sin, Symbol from sympy.printing.mathml import mathml, MathMLPrinter from xml.dom.minidom import parseString -from sympy.utilities.pytest import XFAIL x = Symbol('x') mp = MathMLPrinter() @@ -50,16 +49,23 @@ def test_mathml_functions(): assert mml_2.childNodes[1].nodeName == 'bvar' assert mml_2.childNodes[1].childNodes[0].nodeName == 'ci' # below bvar there's <ci>x/ci> [EMAIL PROTECTED] def test_mathml_limits(): # XXX No unevaluated limits - mml_1 = mp._print(limit(sin(x)/x, x, 0, evaluate=False)) + lim_fun = sin(x)/x + mml_1 = mp._print(Limit(lim_fun, x, 0)) assert mml_1.childNodes[0].nodeName == 'limit' assert mml_1.childNodes[1].nodeName == 'bvar' - assert mml_1.childNodes[1].childNodes[0].nodeName == 'ci' + assert mml_1.childNodes[2].nodeName == 'lowlimit' + assert mml_1.childNodes[3].toxml() == mp._print(lim_fun).toxml() def test_mathml_integrals(): - pass #TODO + integrand = x + mml_1 = mp._print(Integral(integrand, (x, 0, 1))) + assert mml_1.childNodes[0].nodeName == 'int' + assert mml_1.childNodes[1].nodeName == 'bvar' + assert mml_1.childNodes[2].nodeName == 'lowlimit' + assert mml_1.childNodes[3].nodeName == 'uplimit' + assert mml_1.childNodes[4].toxml() == mp._print(integrand).toxml() def test_mathml_matrices(): pass #TODO -- 1.6.0.3 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---