Skip to content

Commit

Permalink
tidy up doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatera committed Nov 12, 2024
1 parent 19e77a1 commit 76ba519
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions sympy/printing/pretty/stringpict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
- minor fixes and changes (mostly to prettyForm)
Updates by Juan Mauricio Matera (email <my last name> 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.
"""
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")))
Expand All @@ -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())
Expand All @@ -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()
Expand Down

0 comments on commit 76ba519

Please sign in to comment.