Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/sage/typeset/ascii_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
n *log(x)
---------
pi
sage: ascii_art(list(Partitions(6)))
sage: ascii_art(list(Partitions(6))) # needs sage.combinat sage.libs.flint
[ * ]
[ ** * ]
[ *** ** * * ]
Expand Down Expand Up @@ -232,21 +232,21 @@ def ascii_art(*obj, **kwds):
We can specify a separator object::

sage: ident = lambda n: identity_matrix(ZZ, n)
sage: ascii_art(ident(1), ident(2), ident(3), sep=' : ')
sage: ascii_art(ident(1), ident(2), ident(3), sep=' : ') # needs sage.modules
[1 0 0]
[1 0] [0 1 0]
[1] : [0 1] : [0 0 1]

We can specify the baseline::

sage: ascii_art(ident(2), baseline=-1) + ascii_art(ident(3))
sage: ascii_art(ident(2), baseline=-1) + ascii_art(ident(3)) # needs sage.modules
[1 0][1 0 0]
[0 1][0 1 0]
[0 0 1]

We can determine the baseline of the separator::

sage: ascii_art(ident(1), ident(2), ident(3), sep=' -- ', sep_baseline=-1)
sage: ascii_art(ident(1), ident(2), ident(3), sep=' -- ', sep_baseline=-1) # needs sage.modules
[1 0 0]
-- [1 0] -- [0 1 0]
[1] [0 1] [0 0 1]
Expand All @@ -255,7 +255,7 @@ def ascii_art(*obj, **kwds):
an ascii art separator::

sage: sep_line = ascii_art('\n'.join(' | ' for _ in range(6)), baseline=6)
sage: ascii_art(*Partitions(6), separator=sep_line, sep_baseline=0)
sage: ascii_art(*Partitions(6), separator=sep_line, sep_baseline=0) # needs sage.combinat sage.libs.flint
| | | | | | | | | | *
| | | | | | | | | ** | *
| | | | | | *** | | ** | * | *
Expand Down
6 changes: 3 additions & 3 deletions src/sage/typeset/character_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ def __format__(self, fmt):

EXAMPLES::

sage: M = matrix([[1,2],[3,4]])
sage: format(ascii_art(M))
sage: M = matrix([[1,2],[3,4]]) # needs sage.modules
sage: format(ascii_art(M)) # needs sage.modules
'[1 2]\n[3 4]'
sage: format(unicode_art(M))
sage: format(unicode_art(M)) # needs sage.modules
'\u239b1 2\u239e\n\u239d3 4\u23a0'
"""
return format(self._string_type(self), fmt)
Expand Down
41 changes: 21 additions & 20 deletions src/sage/typeset/character_art_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def build(self, obj, baseline=None):

EXAMPLES::

sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x))
sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) # needs sage.symbolic
...
sage: result
sage: result # needs sage.symbolic
/
|
| 2
Expand All @@ -99,14 +99,14 @@ def build(self, obj, baseline=None):

TESTS::

sage: n = var('n')
sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo))
sage: n = var('n') # needs sage.symbolic
sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo)) # needs sage.symbolic
/ _________ \
-\2*x + \/ 1 - 4*x - 1/
-------------------------
_________
2*x*\/ 1 - 4*x
sage: ascii_art(list(DyckWords(3)))
sage: ascii_art(list(DyckWords(3))) # needs sage.combinat
[ /\ ]
[ /\ /\ /\/\ / \ ]
[ /\/\/\, /\/ \, / \/\, / \, / \ ]
Expand Down Expand Up @@ -161,10 +161,10 @@ def build_from_magic_method(self, obj, baseline=None):
EXAMPLES::

sage: from sage.typeset.ascii_art import _ascii_art_factory as factory
sage: out = factory.build_from_magic_method(identity_matrix(2)); out
sage: out = factory.build_from_magic_method(identity_matrix(2)); out # needs sage.modules
[1 0]
[0 1]
sage: type(out)
sage: type(out) # needs sage.modules
<class 'sage.typeset.ascii_art.AsciiArt'>
"""
magic_method = getattr(obj, self.magic_method_name)
Expand Down Expand Up @@ -243,12 +243,12 @@ def build_container(self, content, left_border, right_border, baseline=0):

TESTS::

sage: l = ascii_art(list(DyckWords(3))) # indirect doctest
sage: l
sage: l = ascii_art(list(DyckWords(3))) # indirect doctest # needs sage.combinat
sage: l # needs sage.combinat
[ /\ ]
[ /\ /\ /\/\ / \ ]
[ /\/\/\, /\/ \, / \/\, / \, / \ ]
sage: l._breakpoints
sage: l._breakpoints # needs sage.combinat
[9, 17, 25, 33]

Check that zero-height strings are handled (:trac:`28527`)::
Expand Down Expand Up @@ -289,7 +289,7 @@ def build_set(self, s, baseline=0):
iteration over sets is non-deterministic so too is the results of this
test::

sage: ascii_art(set(DyckWords(3))) # indirect doctest random
sage: ascii_art(set(DyckWords(3))) # indirect doctest random # needs sage.combinat
{ /\ }
{ /\ /\/\ /\ / \ }
{ / \/\, / \, /\/\/\, /\/ \, / \ }
Expand All @@ -298,7 +298,7 @@ def build_set(self, s, baseline=0):
a set, but still obtain the same output formatting::

sage: from sage.typeset.ascii_art import _ascii_art_factory as factory
sage: factory.build_set(sorted(set(DyckWords(3))))
sage: factory.build_set(sorted(set(DyckWords(3)))) # needs sage.combinat
{ /\ }
{ /\ /\ /\/\ / \ }
{ /\/\/\, /\/ \, / \/\, / \, / \ }
Expand All @@ -315,6 +315,7 @@ def build_dict(self, d, baseline=0):

TESTS::

sage: # needs sage.combinat
sage: from collections import OrderedDict
sage: d = OrderedDict(enumerate(DyckWords(3)))
sage: art = ascii_art(d) # indirect doctest
Expand Down Expand Up @@ -357,18 +358,18 @@ def build_list(self, l, baseline=0):

TESTS::

sage: l = ascii_art(list(DyckWords(3))) # indirect doctest
sage: l
sage: l = ascii_art(list(DyckWords(3))) # indirect doctest # needs sage.combinat
sage: l # needs sage.combinat
[ /\ ]
[ /\ /\ /\/\ / \ ]
[ /\/\/\, /\/ \, / \/\, / \, / \ ]
sage: l._breakpoints
sage: l._breakpoints # needs sage.combinat
[9, 17, 25, 33]

The breakpoints of the object are used as breakpoints::

sage: l = ascii_art([DyckWords(2).list(), DyckWords(2).list()])
sage: l._breakpoints
sage: l = ascii_art([DyckWords(2).list(), DyckWords(2).list()]) # needs sage.combinat
sage: l._breakpoints # needs sage.combinat
[(2, [7]), 17, (18, [7])]

The parentheses only stretch as high as the content (:trac:`28527`)::
Expand Down Expand Up @@ -399,7 +400,7 @@ def build_tuple(self, t, baseline=0):

TESTS::

sage: ascii_art(tuple(DyckWords(3))) # indirect doctest
sage: ascii_art(tuple(DyckWords(3))) # indirect doctest # needs sage.combinat
( /\ )
( /\ /\ /\/\ / \ )
( /\/\/\, /\/ \, / \/\, / \, / \ )
Expand Down Expand Up @@ -440,8 +441,8 @@ def concatenate(self, iterable, separator, empty=None, baseline=0,

EXAMPLES::

sage: i2 = identity_matrix(2)
sage: ascii_art(i2, i2, i2, sep=ascii_art(1/x))
sage: i2 = identity_matrix(2) # needs sage.modules
sage: ascii_art(i2, i2, i2, sep=ascii_art(1/x)) # needs sage.modules sage.symbolic
1 1
[1 0]-[1 0]-[1 0]
[0 1]x[0 1]x[0 1]
Expand Down
4 changes: 2 additions & 2 deletions src/sage/typeset/unicode_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def unicode_art(*obj, **kwds):
โŽฎ x + ฯ€
โŒก
sage: ident = lambda n: identity_matrix(ZZ, n)
sage: unicode_art(ident(1), ident(2), ident(3), sep=' : ')
sage: unicode_art(ident(1), ident(2), ident(3), sep=' : ') # needs sage.modules
โŽ›1 0 0โŽž
โŽ›1 0โŽž โŽœ0 1 0โŽŸ
(1) : โŽ0 1โŽ  : โŽ0 0 1โŽ 
Expand All @@ -107,7 +107,7 @@ def unicode_art(*obj, **kwds):
an unicode art separator::

sage: sep_line = unicode_art('\n'.join(' โŽŸ ' for _ in range(5)), baseline=5)
sage: unicode_art(*AlternatingSignMatrices(3),
sage: unicode_art(*AlternatingSignMatrices(3), # needs sage.combinat sage.modules
....: separator=sep_line, sep_baseline=1)
โŽŸ โŽŸ โŽŸ โŽŸ โŽŸ โŽŸ
โŽ›1 0 0โŽž โŽŸ โŽ›0 1 0โŽž โŽŸ โŽ›1 0 0โŽž โŽŸ โŽ› 0 1 0โŽž โŽŸ โŽ›0 0 1โŽž โŽŸ โŽ›0 1 0โŽž โŽŸ โŽ›0 0 1โŽž
Expand Down