Okay,

I don't think its possible to do it that way, I put it there so I
could create the text node with 'ⅈ' in it.  Without the
unescape I get ⅈ.  The issue is that I can only run
unescape after toxml() or to toprettyxml() is run on it.  Since the
printing is recursive I have to maintain DOM nodes until the entire
expression is printed.

I'll work on adding some tests and submit a new patch.  I have done
some more work on this since I made the patch.  It took me awhile to
figure out that I had to join this group in order to submit patches to
it, so I just submitted the patch I had made a few weeks ago.  Now
that I know how this works, I'll put together the tests and submit the
new patch later this week.

If there are any other problems with this code that would make it
"prettier" feel free to tell me.  I haven't done alot of work with
python so there may be some standard coding practices for python that
I'm unaware of.

Thanks,
Thomas Sidoti



On May 9, 7:27 am, Fabian Pedregosa <fab...@fseoane.net> wrote:
> Ondrej Certik wrote:
> > Hi Thomas,
>
> > the patch looks good to me, thanks!
>
> > Could you please also write tests for it? That's very important.
>
> > Thanks,
> > Ondrej
>
> > On Thu, May 7, 2009 at 9:10 PM, Thomas Sidoti <tsid...@gmail.com> wrote:
> >> From cd4af400b0793352fd311875ad03ac1e7f3315d5 Mon Sep 17 00:00:00 2001
> >> From: Thomas Sidoti <tsid...@gmail.com>
> >> Date: Wed, 22 Apr 2009 00:06:52 -0400
> >> Subject: [PATCH 1/1] mathml: fixed printing of inverse trig functions,
> >> complex numbers, pi
> >> ---
> >>  sympy/printing/mathml.py |   41 ++++++++++++++++++++++++++++++++++++-----
> >>  1 files changed, 36 insertions(+), 5 deletions(-)
> >> diff --git a/sympy/printing/mathml.py b/sympy/printing/mathml.py
> >> index 3bc1ae2..160aad9 100644
> >> --- a/sympy/printing/mathml.py
> >> +++ b/sympy/printing/mathml.py
> >> @@ -4,6 +4,8 @@ A MathML printer.
>
> >>  from sympy import Basic, sympify
> >>  from printer import Printer
> >> +from xml.sax import saxutils
> >> +
>
> >>  class MathMLPrinter(Printer):
> >>      """Prints an expression to the MathML markup language
> >> @@ -20,7 +22,9 @@ class MathMLPrinter(Printer):
> >>          self.dom = Document()
>
> >>      def doprint(self, e):
> >> -        return self._print(e).toxml()
> >> +        #return self._print(e).toxml()
> >> +        mathML = Printer.doprint(self,expr)
> >> +        return mathML.toxml()
>
> >>      def mathml_tag(self, e):
> >>          """Returns the MathML tag for an expression."""
> >> @@ -32,14 +36,26 @@ class MathMLPrinter(Printer):
> >>              'int': 'cn',
> >>              'Pow': 'power',
> >>              'Symbol': 'ci',
> >> -            'Integral': 'int'
> >> +            'Integral': 'int',
> >> +            'sin': 'sin',
> >> +            'cos': 'cos',
> >> +            'tan': 'tan',
> >> +            'cot': 'cot',
> >> +            'asin': 'arcsin',
> >> +            'asinh': 'arcsinh',
> >> +            'acos': 'arccos',
> >> +            'acosh': 'arccosh',
> >> +            'atan': 'arctan',
> >> +            'atanh': 'arctanh',
> >> +            'acot': 'arccot',
> >> +            'atan2': 'arctan',
> >> +            'log': 'ln'
> >>          }
>
> >>          for cls in e.__class__.__mro__:
> >>              n = cls.__name__
> >>              if n in translate:
> >>                  return translate[n]
> >> -
> >>          # Not found in the MRO set
> >>          n = e.__class__.__name__
> >>          return n.lower()
> >> @@ -65,9 +81,24 @@ class MathMLPrinter(Printer):
> >>          x.appendChild(x_1)
> >>          x.appendChild(x_2)
> >>          x.appendChild(self._print(e.args[0]))
> >> -
> >>          return x
>
> >> +    def _print_ImaginaryUnit(self,e):
> >> +        x = self.dom.createElement('cn')
> >> +        x.appendChild(self.dom.createTextNode('&ImaginaryI;'))
> >> +        return x;
> >> +
> >> +    def _print_Pi(self, e):
> >> +        return self.dom.createElement('pi')
> >> +
> >> +    def _print_Infinity(self, e):
> >> +        return self.dom.createElement('infinity')
> >> +
> >> +    def _print_Negative_Infinity(self,e):
> >> +        x = self.dom.createElement('apply')
> >> +        x.appendChild(self.dom.createElement('minus'))
> >> +        x.appendChild(self.dom.createElement('infinity'))
> >> +        return x
>
> >>      def _print_Integral(self, e):
> >>          def lime_recur(limits):
> >> @@ -182,4 +213,4 @@ def print_mathml(expr):
> >>      </apply>
> >>      """
> >>      s = MathMLPrinter()
> >> -    print s._print(sympify(expr)).toprettyxml()
> >> +    print saxutils.unescape(s._print(sympify(expr)).toprettyxml())
>
> I think this is ugly. If something should be unescaped it should be done
> inside the _print_* methods. Do you have an example where this is needed
>   so that we can fix it?
>
> Thanks,
>
> >> --
> >> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to