Ticket #11775: trac_11775-pretty_print_multiple_args.patch

File trac_11775-pretty_print_multiple_args.patch, 2.5 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 1317393015 25200
    # Node ID a5526ce127658e2865704fd6c30f8cde603c0a45
    # Parent 8a0b4f90f1ca76dbdba159897c39209c5da85442
    trac #11775: make pretty_print accept multiple arguments
    
    diff --git a/sage/misc/latex.py b/sage/misc/latex.py
    a b  
    21202120    else:
    21212121        print(object)
    21222122
    2123 def pretty_print (object):
     2123def pretty_print (*args):
    21242124    r"""
    21252125    Try to pretty print an object in an intelligent way.  For graphics
    21262126    objects, this returns their default representation.  For other
     
    21392139
    21402140        sage: from sage.misc.latex import pretty_print
    21412141        sage: pretty_print(ZZ)  # indirect doctest
    2142         <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z}</span></html>
     2142        <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\verb|$\Bold{Z}$|</span></html>
     2143        sage: pretty_print("Integers = ", ZZ, ", $\\frac{d(x^3)}{dx} =$ ", derivative(x^3, x)) # test multiple inputs
     2144        <html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\verb|Integers|\phantom{x}\verb|=|\phantom{x}\verb|$\Bold{Z}$,|\phantom{x}\verb|$\frac{d(x^3)}{dx}|\phantom{x}\verb|=$|\phantom{x}\verb|$3|\phantom{x}\verb|\,|\phantom{x}\verb|x^{2}$|</span></html>
    21432145    """
    2144     if object is None:
    2145         return
    2146     import __builtin__
    2147     __builtin__._=object
    2148 
    2149     from sage.plot.plot import Graphics
    2150     from sage.plot.plot3d.base import Graphics3d
    2151     if isinstance(object, (Graphics, Graphics3d)):
    2152         print repr(object)
    2153         return
    2154     else:
    2155         if EMBEDDED_MODE:
    2156             view(object)
     2146    # view s if it is not empty. Used twice.
     2147    def _show_s(s):
     2148        if not s == '':
     2149            if EMBEDDED_MODE:
     2150                view(s)
     2151            else:
     2152                print JSMath().eval(s, mode='inline')
     2153
     2154    s = ''
     2155    for object in args:
     2156        if object is None:
     2157            continue
     2158
     2159        import __builtin__
     2160        __builtin__._=object
     2161
     2162        from sage.plot.plot import Graphics
     2163        from sage.plot.plot3d.base import Graphics3d
     2164        if isinstance(object, (Graphics, Graphics3d)):
     2165            _show_s(s)
     2166            s = ''
     2167            print repr(object)
     2168
    21572169        else:
    2158             print JSMath().eval(object, mode='inline')
    2159         return
     2170            s += ('$'+object._latex_()+'$' if hasattr(object, '_latex_')
     2171                    else str(object))
     2172
     2173    _show_s(s)
     2174    return
    21602175
    21612176def pretty_print_default(enable=True):
    21622177    r"""