Ticket #11775: pretty_print_multiple_args.diff

File pretty_print_multiple_args.diff, 2.7 KB (added by ppurka, 10 years ago)

The patch to pretty_print and pretty_print_default

  • sage/misc/latex.py

    # HG changeset patch
    # User P Purkayastha <ppurka@gmail.com>
    # Date 1315137052 -28800
    # Node ID a5526ce127658e2865704fd6c30f8cde603c0a45
    # Parent  4198d41f9a77a2b7a7e01657143de17dede7c3e5
    [mq]: pretty_print_multiple_args
    
    diff --git a/sage/misc/latex.py b/sage/misc/latex.py
    a b  
    20682068    else:
    20692069        print(object)
    20702070
    2071 def pretty_print (object):
     2071def pretty_print (*args):
    20722072    r"""
    20732073    Try to pretty print an object in an intelligent way.  For graphics
    20742074    objects, this returns their default representation.  For other
     
    20872087
    20882088        sage: from sage.misc.latex import pretty_print
    20892089        sage: pretty_print(ZZ)  # indirect doctest
    2090         <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}</span></html>
     2090        <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{$\Bold{Z}$}</span></html>
     2091        sage: pretty_print("Integers = ", ZZ, ", $\\frac{d(x^3)}{dx} =$ ", derivative(x^3, x)) # test multiple inputs
     2092        <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{Integers = $\Bold{Z}$, $\frac{d(x^3)}{dx} =$ $3 \, x^{2}$}</span></html>
    20912093    """
    2092     if object is None:
    2093         return
    2094     import __builtin__
    2095     __builtin__._=object
    2096 
    2097     from sage.plot.plot import Graphics
    2098     from sage.plot.plot3d.base import Graphics3d
    2099     if isinstance(object, (Graphics, Graphics3d)):
    2100         print repr(object)
    2101         return
    2102     else:
    2103         if EMBEDDED_MODE:
    2104             view(object)
     2094    # view s if it is not empty. Used twice.
     2095    def _show_s(s):
     2096        if not s == '':
     2097            if EMBEDDED_MODE:
     2098                view(s)
     2099            else:
     2100                print JSMath().eval(s, mode='inline')
     2101
     2102    s = ''
     2103    for object in args:
     2104        if object is None:
     2105            continue
     2106
     2107        import __builtin__
     2108        __builtin__._=object
     2109
     2110        from sage.plot.plot import Graphics
     2111        from sage.plot.plot3d.base import Graphics3d
     2112        if isinstance(object, (Graphics, Graphics3d)):
     2113            _show_s(s)
     2114            s = ''
     2115            print repr(object)
     2116
    21052117        else:
    2106             print JSMath().eval(object, mode='inline')
    2107         return
     2118            s += ('$'+object._latex_()+'$' if hasattr(object, '_latex_')
     2119                    else str(object))
     2120
     2121    _show_s(s)
     2122    return
    21082123
    21092124def pretty_print_default(enable=True):
    21102125    r"""
     
    21212136
    21222137        sage: pretty_print_default(True)
    21232138        sage: sys.displayhook
    2124         <html><span class="math">...\hbox{ < function pretty_print at ... > }</span></html>
     2139        <html><span class="math">...\hbox{<function pretty_print at ...>}</span></html>
    21252140        sage: pretty_print_default(False)
    21262141        sage: sys.displayhook == sys.__displayhook__
    21272142        True