Ah, that's because Matrix doesn't subclass from Basic. You'll have to hook it separately if you want it to work too.
By the way, forcing people to override Basic.__str__ is probably a bad design. This was discussed a bit last summer with Gilbert's GSoC project as I remember. Any thoughts on a better way to do this? Aaron Meurer On Tue, Apr 17, 2012 at 5:26 PM, Alan Bromborsky <abro...@verizon.net> wrote: > On 04/17/2012 06:48 PM, Aaron Meurer wrote: >> >> On Tue, Apr 17, 2012 at 4:41 PM, Alan Bromborsky<abro...@verizon.net> >> wrote: >>> >>> On 04/17/2012 06:28 PM, Aaron Meurer wrote: >>>> >>>> print executes str(), so the only way to make print do that is to >>>> override __str__. If you just want it for your own custom classes, >>>> you can just override __str__ in those classes. Otherwise, you'll >>>> have to hook Basic.__str__, as described at >>>> http://docs.sympy.org/0.7.1/modules/printing.html. >>>> >>>> Aaron Meurer >>>> >>>> On Tue, Apr 17, 2012 at 4:19 PM, Alan Bromborsky<abro...@verizon.net> >>>> wrote: >>>>> >>>>> I have written my own extensions to LatexPrinting (its parent class is >>>>> LatexPrinting) and it works fine, but is there a global way so that >>>>> >>>>> print A >>>>> >>>>> will actually execute >>>>> >>>>> print latex(A) >>>>> >>>>> so that I have to make fewer changes between terminal and latex >>>>> printing >>>>> in >>>>> the code. >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups >>>>> "sympy" group. >>>>> To post to this group, send email to sympy@googlegroups.com. >>>>> To unsubscribe from this group, send email to >>>>> sympy+unsubscr...@googlegroups.com. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/sympy?hl=en. >>>>> >>> I assume you mean - >>> >>> Basic.__str__ = lambda self: CustomStrPrinter().doprint(self) >>> >>> I have two custom printer classes - >>> >>> class GA_Printer(StrPrinter): >>> >>> and >>> >>> class GA_LatexPrinter(LatexPrinter): >>> >>> when I do - >>> >>> Basic.__str__ = lambda self: GA_Printer().doprint(self) >>> >>> it works fine, but >>> >>> Basic.__str__ = lambda self: GA_LatexPrinter().doprint(self) >>> >>> still requires >>> >>> print latex(A) >>> >>> instead of >>> >>> print A >>> >>> I assume this is because GA_LatexPrinter is not derived from StrPrinter. >>> Is >>> there a way to make this work with modifying LatexPrinter or >>> StrPrinter? >> >> This doesn't make sense. For the same object A, it should work the >> same. The printer itself should have nothing to do with it, as long >> as it returns a string. What does "print A" do when you set >> >> Basic.__str__ = lambda self: GA_LatexPrinter().doprint(self) >> >> Aaron Meurer >> > Code - > > from sympy import * > from GA import MV,Format > from GAPrint import enhance_print,xdvi,GA_LatexPrinter > > > Basic.__str__ = lambda self: GA_LatexPrinter().doprint(self) > > > (a,b,x,y) = symbols('a b x y') > > M = Matrix([[a,b],[x,y]]) > > print M > > Result - > > [a, b] > [x, y] > > Code - > > from sympy import * > from GA import MV,Format > from GAPrint import enhance_print,xdvi,GA_LatexPrinter > > > Basic.__str__ = lambda self: GA_LatexPrinter().doprint(self) > > (a,b,x,y) = symbols('a b x y') > > M = Matrix([[a,b],[x,y]]) > > print latex(M) > > Result - > > \left[\begin{smallmatrix}a & b\\x & y\end{smallmatrix}\right] > > > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sympy@googlegroups.com. > To unsubscribe from this group, send email to > sympy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.