# HG changeset patch # User P Purkayastha # 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/sage/misc/latex.py +++ b/sage/misc/latex.py @@ -2077,7 +2077,7 @@ else: print(object) -def pretty_print (object): +def pretty_print (*args): r""" Try to pretty print an object in an intelligent way. For graphics objects, this returns their default representation. For other @@ -2096,24 +2096,39 @@ sage: from sage.misc.latex import pretty_print sage: pretty_print(ZZ) # indirect doctest - \newcommand{\Bold}[1]{\mathbf{#1}}\Bold{Z} + \newcommand{\Bold}[1]{\mathbf{#1}}\hbox{$\Bold{Z}$} + sage: pretty_print("Integers = ", ZZ, ", $\\frac{d(x^3)}{dx} =$ ", derivative(x^3, x)) # test multiple inputs + \newcommand{\Bold}[1]{\mathbf{#1}}\hbox{Integers = $\Bold{Z}$, $\frac{d(x^3)}{dx} =$ $3 \, x^{2}$} """ - if object is None: - return - import __builtin__ - __builtin__._=object - - from sage.plot.plot import Graphics - from sage.plot.plot3d.base import Graphics3d - if isinstance(object, (Graphics, Graphics3d)): - print repr(object) - return - else: - if EMBEDDED_MODE: - view(object) + # view s if it is not empty. Used twice. + def _show_s(s): + if not s == '': + if EMBEDDED_MODE: + view(s) + else: + print JSMath().eval(s, mode='inline') + + s = '' + for object in args: + if object is None: + continue + + import __builtin__ + __builtin__._=object + + from sage.plot.plot import Graphics + from sage.plot.plot3d.base import Graphics3d + if isinstance(object, (Graphics, Graphics3d)): + _show_s(s) + s = '' + print repr(object) + else: - print JSMath().eval(object, mode='inline') - return + s += ('$'+object._latex_()+'$' if hasattr(object, '_latex_') + else str(object)) + + _show_s(s) + return def pretty_print_default(enable=True): r""" @@ -2130,7 +2145,7 @@ sage: pretty_print_default(True) sage: sys.displayhook - ...\hbox{ < function pretty_print at ... > } + ...\hbox{} sage: pretty_print_default(False) sage: sys.displayhook == sys.__displayhook__ True