diff --git a/sympy/printing/pretty/stringpict.py b/sympy/printing/pretty/stringpict.py index 3ae09b2fa783..09b0c213c67c 100644 --- a/sympy/printing/pretty/stringpict.py +++ b/sympy/printing/pretty/stringpict.py @@ -8,10 +8,10 @@ - minor fixes and changes (mostly to prettyForm) Updates by Juan Mauricio Matera (email at ar_ude_plnu_acisif): - - support for align attribute in `left`, `right`, `above` and `bellow` + - support for align attribute in `left`, `right`, `above` and `below` methods - adding the v_align() method - - Methods `parens`, `left`, `right`, `above` and `bellow` now returns + - Methods `parens`, `left`, `right`, `above` and `below` now returns objects of the caller object class. - The method `root` now works. """ @@ -248,6 +248,8 @@ def below(self, *args, align="c"): Examples ======== + Let' s consider first how to draw a fraction:: + >>> from sympy.printing.pretty.stringpict import stringPict >>> print(stringPict("x+3").below( ... stringPict.LINE, '3')) #doctest: +NORMALIZE_WHITESPACE @@ -257,27 +259,32 @@ def below(self, *args, align="c"): The optional argument `align` controls the alignment. The default value is `'c'`. For `align='l'`, - the text is left aligned: + the text is left aligned:: >>> print(stringPict("Humpty Dumpty").below( ... stringPict("falls off the wall..."), align="l")) Humpty Dumpty falls off the wall... - and for `align='r'`, the elements are right aligned: + and for `align='r'`, the elements are right aligned:: + >>> print(stringPict("Humpty Dumpty").below( ... stringPict("falls off the wall..."), align="r")) - Humpty Dumpty + Humpty Dumpty falls off the wall... - """ s, baseline = stringPict.stack(self, *args, align=align) return self.__class__(s, self.baseline) def above(self, *args, align="c"): - """Put pictures above this picture. + """ + Put pictures above this picture. + Returns string, baseline arguments for stringPict. Baseline is baseline of bottom picture. + the horizontal alignment is controlled by the keyword + parameter `align`. See stringPict.below() for details and + examples. """ string, baseline = stringPict.stack(*(args + (self,)), align=align) baseline = len(string.splitlines()) - self.height() + self.baseline @@ -319,7 +326,8 @@ def leftslash(self): return self.left(stringPict(slash, height // 2)) def root(self, n=None): - """Produce a nice root symbol. + """ + Produce a nice root symbol. Produces ugly results for big n inserts. >>> from sympy.printing.pretty.stringpict import stringPict, prettyForm @@ -362,11 +370,10 @@ def root(self, n=None): /x+3\\ |---| + a \\ y / - """ - # XXX not used anywhere - # XXX duplicate of root drawing in pretty.py - #put line over expression + # TODO: use it in root drawing in PrettyPrinter. + # + # put line over expression if n is not None: if isinstance(n, str): n = stringPict(n) @@ -476,8 +483,11 @@ def chunks(line): return "\n\n".join(pictures) def subindex(self, sub_index): - """ - Add a `subindex`. + """Add a `subindex`. + + Examples + ======== + >>> from sympy.printing.pretty.stringpict import stringPict >>> print( (stringPict("a").below("-").below(stringPict("b")) ... ).parens().subindex(stringPict("a=4"))) @@ -496,13 +506,15 @@ def subsuperindices(self, sub_index, super_index): """ Add sub and super indices. + Examples + ======== + >>> from sympy.printing.pretty.stringpict import stringPict >>> print(stringPict("T").subsuperindices( ... stringPict("a"),stringPict("b,c"))) b,c T a - """ width_self = self.width() width_index = max(sub_index.width() ,super_index.width()) @@ -518,11 +530,13 @@ def superindex(self, super_index): """ Add a `super index`. + Examples + ======== + >>> from sympy.printing.pretty.stringpict import stringPict >>> print(stringPict("e").superindex(stringPict("-s(x)"))) -s(x) e - """ width_self = self.width() width_index = super_index.width()