>From d11d7e2c1a52af277ab14b95b49c1e320aa87206 Mon Sep 17 00:00:00 2001
From: Thomas Sidoti <tsid...@gmail.com>
Date: Sun, 24 May 2009 16:46:27 -0400
Subject: [PATCH 2/2] added tests, EulerGamma, removed pretty

---
 sympy/printing/mathml.py            |   24 ++++++++++++++----------
 sympy/printing/tests/test_mathml.py |    8 +++++++-
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/sympy/printing/mathml.py b/sympy/printing/mathml.py
index d057b03..72aec44 100644
--- a/sympy/printing/mathml.py
+++ b/sympy/printing/mathml.py
@@ -88,7 +88,7 @@ class MathMLPrinter(Printer):
             x.appendChild(self._print(term))
         return x

-    """This is complicated because we attempt to order then results in
order of Basic._compare_pretty and use minus instaed of negative"""
+    #This is complicated because we attempt to order then results in order
of Basic._compare_pretty and use minus instead of negative
     def _print_Add(self, e):
         args = list(e.args)
         args.sort(Basic._compare_pretty)
@@ -99,12 +99,12 @@ class MathMLPrinter(Printer):
             arg = args[i]
             coeff, terms = arg.as_coeff_terms()
             if(coeff.is_negative):
-                """use minus"""
+                #use minus
                 x = self.dom.createElement('apply')
                 x.appendChild(self.dom.createElement('minus'))
                 x.appendChild(lastProcessed)
                 x.appendChild(self._print(-arg))
-                """invert expression  since this is now minused"""
+                #invert expression  since this is now minused
                 lastProcessed = x;
                 if(arg == args[-1]):
                     plusNodes.append(lastProcessed)
@@ -132,16 +132,16 @@ class MathMLPrinter(Printer):

     def _print_Rational(self, e):
         if e.q == 1:
-            """don't divide"""
+            #don't divide
             x = self.dom.createElement('cn')
             x.appendChild(self.dom.createTextNode(str(e.p)))
             return x
         x = self.dom.createElement('apply')
         x.appendChild(self.dom.createElement('divide'))
-        """numerator"""
+        #numerator
         xnum = self.dom.createElement('cn')
         xnum.appendChild(self.dom.createTextNode(str(e.p)))
-        """denomenator"""
+        #denomenator
         xdenom = self.dom.createElement('cn')
         xdenom.appendChild(self.dom.createTextNode(str(e.q)))
         x.appendChild(xnum)
@@ -165,10 +165,14 @@ class MathMLPrinter(Printer):
     def _print_ImaginaryUnit(self,e):
         return self.dom.createElement('imaginaryi')

+    def _print_EulerGamma(self,e):
+        x = self.dom.createElement('cn')
+        x.appendChild(self.dom.createTextNode('&gamma;'))
+        return x;
+
     def _print_GoldenRatio(self,e):
         x = self.dom.createElement('cn')
-        """This is an html phi"""
-        x.appendChild(self.dom.createTextNode('&#981;'))
+        x.appendChild(self.dom.createTextNode('&Phi;'))
         return x;

     def _print_Exp1(self,e):
@@ -217,7 +221,7 @@ class MathMLPrinter(Printer):
         return x

     def _print_Pow(self, e):
-        """Here we use root instead of power if the exponent is the
reciprocal of an integer"""
+        #Here we use root instead of power if the exponent is the
reciprocal of an integer
         if e.exp.is_Rational and e.exp.p == 1:
             x = self.dom.createElement('apply')
             x.appendChild(self.dom.createElement('root'))
@@ -291,7 +295,7 @@ class MathMLPrinter(Printer):
 def mathml(expr):
     """Returns the MathML representation of expr"""
     s = MathMLPrinter()
-    return saxutils.unescape(s._print(sympify(expr)).toprettyxml())
+    return saxutils.unescape(s._print(sympify(expr)).toxml())

 def print_mathml(expr):
     """
diff --git a/sympy/printing/tests/test_mathml.py
b/sympy/printing/tests/test_mathml.py
index 52aea8a..087656d 100644
--- a/sympy/printing/tests/test_mathml.py
+++ b/sympy/printing/tests/test_mathml.py
@@ -1,4 +1,4 @@
-from sympy import diff, Integral, Limit, sin, Symbol, Integer, Rational,
cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, E, I, oo,
pi
+from sympy import diff, Integral, Limit, sin, Symbol, Integer, Rational,
cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, E, I, oo,
pi, GoldenRatio, EulerGamma
 from sympy.printing.mathml import mathml, MathMLPrinter
 from xml.dom.minidom import parseString

@@ -110,6 +110,12 @@ def test_mathml_constants():
     mml = mp._print(pi)
     assert mml.nodeName == 'pi'

+    mml = mathml(GoldenRatio)
+    assert mml == '<cn>&Phi;</cn>'
+
+    mml = mathml(EulerGamma)
+    assert mml == '<cn>&gamma;</cn>'
+
 def test_mathml_trig():
     mml = mp._print(sin(x))
     assert mml.childNodes[0].nodeName == 'sin'
-- 
1.5.6.5

--~--~---------~--~----~------------~-------~--~----~
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 
sympy-patches+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sympy-patches?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: 0001-MathML-trig-functions-order-of-terms-roots-and-c.patch
Description: Binary data

Attachment: 0002-added-tests-EulerGamma-removed-pretty.patch
Description: Binary data

Reply via email to