Ticket #11775: 11775-pretty_print_multiple_args.patch

File 11775-pretty_print_multiple_args.patch, 2.8 KB (added by kini, 10 years ago)

apply to $SAGE_ROOT/devel/sage

  • sage/misc/latex.py

    # HG changeset patch
    # User P Purkayastha <ppurka@gmail.com>
    # Date 1315137052 -28800
    # Node ID a5526ce127658e2865704fd6c30f8cde603c0a45
    # Parent 2a2abbcad325ccca9399981ceddf5897eb467e64
    trac #11775: make pretty_print accept multiple arguments
    
    diff --git a/sage/misc/latex.py b/sage/misc/latex.py
    a b  
    20772077    else:
    20782078        print(object)
    20792079
    2080 def pretty_print (object):
     2080def pretty_print (*args):
    20812081    r"""
    20822082    Try to pretty print an object in an intelligent way.  For graphics
    20832083    objects, this returns their default representation.  For other
     
    20962096
    20972097        sage: from sage.misc.latex import pretty_print
    20982098        sage: pretty_print(ZZ)  # indirect doctest
    2099         <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}</span></html>
     2099        <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{$\Bold{Z}$}</span></html>
     2100        sage: pretty_print("Integers = ", ZZ, ", $\\frac{d(x^3)}{dx} =$ ", derivative(x^3, x)) # test multiple inputs
     2101        <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{Integers = $\Bold{Z}$, $\frac{d(x^3)}{dx} =$ $3 \, x^{2}$}</span></html>
    21002102    """
    2101     if object is None:
    2102         return
    2103     import __builtin__
    2104     __builtin__._=object
    2105 
    2106     from sage.plot.plot import Graphics
    2107     from sage.plot.plot3d.base import Graphics3d
    2108     if isinstance(object, (Graphics, Graphics3d)):
    2109         print repr(object)
    2110         return
    2111     else:
    2112         if EMBEDDED_MODE:
    2113             view(object)
     2103    # view s if it is not empty. Used twice.
     2104    def _show_s(s):
     2105        if not s == '':
     2106            if EMBEDDED_MODE:
     2107                view(s)
     2108            else:
     2109                print JSMath().eval(s, mode='inline')
     2110
     2111    s = ''
     2112    for object in args:
     2113        if object is None:
     2114            continue
     2115
     2116        import __builtin__
     2117        __builtin__._=object
     2118
     2119        from sage.plot.plot import Graphics
     2120        from sage.plot.plot3d.base import Graphics3d
     2121        if isinstance(object, (Graphics, Graphics3d)):
     2122            _show_s(s)
     2123            s = ''
     2124            print repr(object)
     2125
    21142126        else:
    2115             print JSMath().eval(object, mode='inline')
    2116         return
     2127            s += ('$'+object._latex_()+'$' if hasattr(object, '_latex_')
     2128                    else str(object))
     2129
     2130    _show_s(s)
     2131    return
    21172132
    21182133def pretty_print_default(enable=True):
    21192134    r"""
     
    21302145
    21312146        sage: pretty_print_default(True)
    21322147        sage: sys.displayhook
    2133         <html><span class="math">...\hbox{ < function pretty_print at ... > }</span></html>
     2148        <html><span class="math">...\hbox{<function pretty_print at ...>}</span></html>
    21342149        sage: pretty_print_default(False)
    21352150        sage: sys.displayhook == sys.__displayhook__
    21362151        True