Jason Grout wrote: > William Stein wrote: >> On Jan 24, 2008 9:43 PM, Jason Grout <[EMAIL PROTECTED]> wrote: >>> Following up on William's tip to look at the displayhook function, here >>> is a function that will enable "pretty-printing" by default in the notebook: >>> >>> def pretty_print (object): >>> if object is None: >>> return >>> import __builtin__ >>> __builtin__._=object >>> try: >>> print html("$"+latex(object)+"$") >>> except: >>> import sys >>> sys.__displayhook__(object) >>> >>> def notebook_pretty(enable=True): >>> import sys >>> if enable: >>> sys.displayhook = pretty_print >>> else: >>> sys.displayhook = sys.__displayhook__ >>> >>> # To enable the pretty-printing >>> notebook_pretty(True) >>> >>> Of course the function names could (and probably should) change. This >>> function makes the notebook much, much more user-friendly to new users, >>> I think. Where should this function be located? Also, should it be a >>> switch at the top of the notebook, like the evaluation drop-down menu? >>> >>> One problem with the above is that graphics objects are not shown by >>> default (try doing plot(sin(x),1,2) after the above code). Someone >>> familiar with how graphic objects are shown by default now could >>> probably trivially fix that problem, though (any takers?). >>> >> Sure. This is like yours but slightly nicer and deals with graphics >> nicely (and also lists of graphics objects): >> >> def pretty_print (object): >> if object is None: >> return >> if isinstance(object, (sage.plot.plot.Graphics, >> sage.plot.plot3d.base.Graphics3d)): >> print repr(object) >> return >> import __builtin__ >> __builtin__._=object >> try: >> print html("$$"+latex(object)+"$$") >> except: >> import sys >> sys.__displayhook__(object) >> >> def notebook_pretty(enable=True): >> import sys >> if enable: >> sys.displayhook = pretty_print >> else: >> sys.displayhook = sys.__displayhook__ >> >> # To enable the pretty-printing >> notebook_pretty(True) > > mhansen and mabshoff just pointed out on IRC that lprint() is the > existing function that is almost exactly this. So I'm patching up > lprint instead.
A patch is up at #1922. Could someone review it, please? > > Can we make a very visible checkbox or button in the notebook interface > that toggles lprint? I think it would be one thing that new users would > appreciate very, very much and also someone like me would appreciate > very much too. This is trac #1923 Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---