# HG changeset patch # User P Purkayastha # Date 1317468945 25200 # Node ID a5526ce127658e2865704fd6c30f8cde603c0a45 # Parent 8a0b4f90f1ca76dbdba159897c39209c5da85442 trac #11775: make pretty_print accept multiple arguments diff --git a/doc/de/tutorial/latex.rst b/doc/de/tutorial/latex.rst --- a/doc/de/tutorial/latex.rst +++ b/doc/de/tutorial/latex.rst @@ -136,9 +136,9 @@ sage: from sage.misc.latex import pretty_print sage: pretty_print(x^12) - \newcommand{\Bold}[1]{\mathbf{#1}}x^{12} + \newcommand{\Bold}[1]{\mathbf{#1}}\verb|$x^{12}$| sage: pretty_print(integrate(sin(x), x)) - \newcommand{\Bold}[1]{\mathbf{#1}}-\cos\left(x\right) + \newcommand{\Bold}[1]{\mathbf{#1}}\verb|$-\cos\left(x\right)$| Das Notebook hat zwei weitere Möglichkeiten TeX zu nutzen. Die erste ist der "Typeset"-Knopf über der ersten Zelle eines Arbeitsblatts, diff --git a/doc/en/tutorial/latex.rst b/doc/en/tutorial/latex.rst --- a/doc/en/tutorial/latex.rst +++ b/doc/en/tutorial/latex.rst @@ -139,9 +139,9 @@ sage: from sage.misc.latex import pretty_print sage: pretty_print(x^12) - \newcommand{\Bold}[1]{\mathbf{#1}}x^{12} + \newcommand{\Bold}[1]{\mathbf{#1}}\verb|$x^{12}$| sage: pretty_print(integrate(sin(x), x)) - \newcommand{\Bold}[1]{\mathbf{#1}}-\cos\left(x\right) + \newcommand{\Bold}[1]{\mathbf{#1}}\verb|$-\cos\left(x\right)$| The notebook has two other features for employing TeX. The first is the "Typeset" button just above the first cell of a diff --git a/sage/misc/latex.py b/sage/misc/latex.py --- a/sage/misc/latex.py +++ b/sage/misc/latex.py @@ -2120,7 +2120,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 @@ -2139,24 +2139,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}}\verb|$\Bold{Z}$| + sage: pretty_print("Integers = ", ZZ, ", $\\frac{d(x^3)}{dx} =$ ", derivative(x^3, x)) # test multiple inputs + \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}$| """ - 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"""