Factory for Character-Based Art

class sage.typeset.character_art_factory.CharacterArtFactory(art_type, string_type, magic_method_name, parenthesis, square_bracet, curly_brace)

Bases: sage.structure.sage_object.SageObject

Abstract base class for character art factory

This class is the common implementation behind ascii_art() and unicode_art() .

INPUT:

  • art_type – type of the character art (i.e. a subclass of CharacterArt)
  • string_type – type of strings (the lines in the character art, e.g. str or unicode).
  • magic_method_name – name of the Sage magic method (e.g. '_ascii_art_' or '_unicode_art_').
  • parenthesis – left/right pair of two multi-line symbols. The parenthesis, a.k.a. round brackets (used for printing tuples).
  • square_bracket – left/right pair of two multi-line symbols. The square_brackets (used for printing lists).
  • curly_brace – left/right pair of two multi-line symbols. The curly braces (used for printing sets).

EXAMPLES:

sage: from sage.typeset.ascii_art import _ascii_art_factory as factory
sage: type(factory)
<class 'sage.typeset.character_art_factory.CharacterArtFactory'>
build(obj)

Construct a character art representation

INPUT:

  • obj – anything. The object whose ascii art representation we want.

OUTPUT:

Character art object.

EXAMPLES:

sage: ascii_art(integral(exp(x+x^2)/(x+1), x))
    /
   |
   |   2
   |  x  + x
   | e
   | ------- dx
   |  x + 1
   |
  /

TESTS:

sage: n = var('n')
sage: ascii_art(sum(binomial(2 * n, n + 1) * x^n, n, 0, oo))
 /        __________    \
-\2*x + \/ -4*x + 1  - 1/
--------------------------
           __________
     2*x*\/ -4*x + 1
sage: ascii_art(list(DyckWords(3)))
[                                   /\   ]
[            /\    /\      /\/\    /  \  ]
[ /\/\/\, /\/  \, /  \/\, /    \, /    \ ]
sage: ascii_art(1)
1
build_container(content, left_border, right_border)

Return character art for a container

INPUT:

  • contentCharacterArt. The content of the container, usually comma-separated entries.
  • left_borderCompoundSymbol. The left border of the container.
  • right_borderCompoundSymbol. The right border of the container.

TESTS:

sage: l = ascii_art(list(DyckWords(3)));  l
[                                   /\   ]
[            /\    /\      /\/\    /  \  ]
[ /\/\/\, /\/  \, /  \/\, /    \, /    \ ]
sage: l.get_breakpoints()
[9, 17, 25, 33]
build_dict(d)

Return an character art output of a dictionary.

TESTS:

sage: d = ascii_art({i:dw for i,dw in enumerate(DyckWords(3))})
sage: d
{                                             /\   }
{                /\      /\        /\/\      /  \  }
{ 0:/\/\/\, 1:/\/  \, 2:/  \/\, 3:/    \, 4:/    \ }
sage: d.get_breakpoints()
[11, 21, 31, 41]
build_empty()

Return the empty character art object

OUTPUT:

Character art instance.

build_from_magic_method(obj)

Return the character art object created by the object’s magic method

OUTPUT:

Character art instance.

EXAMPLES:

sage: from sage.typeset.ascii_art import _ascii_art_factory as factory
sage: out = factory.build_from_magic_method(identity_matrix(2));  out
[1 0]
[0 1]
sage: type(out)
<class 'sage.typeset.ascii_art.AsciiArt'>
build_from_string(obj)

Return the character art object created from splitting the object’s string representation

INPUT:

  • obj – utf-8 encoded byte string or unicode.

OUTPUT:

Character art instance.

EXAMPLES:

sage: from sage.typeset.ascii_art import _ascii_art_factory as factory
sage: out = factory.build_from_string('a\nbb\nccc')
sage: out + out + out
a  a  a
bb bb bb
ccccccccc
sage: type(out)
<class 'sage.typeset.ascii_art.AsciiArt'>

TESTS:

sage: factory.build_from_string(u'a\nbb\nccc')  # same with unicode
a
bb
ccc
build_list(l)

Return an character art output of a list.

TESTS:

sage: l = ascii_art(list(DyckWords(3)));  l
[                                   /\   ]
[            /\    /\      /\/\    /  \  ]
[ /\/\/\, /\/  \, /  \/\, /    \, /    \ ]
sage: l.get_breakpoints()
[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.get_breakpoints()
[9, 17, 25]
build_set(s)

Return an character art output of a set.

TESTS:

sage: ascii_art(set(DyckWords(3)))
{                                   /\   }
{  /\      /\/\              /\    /  \  }
{ /  \/\, /    \, /\/\/\, /\/  \, /    \ }
build_tuple(t)

Return an character art output of a tuple.

TESTS:

sage: ascii_art(tuple(DyckWords(3)))
(                                   /\   )
(            /\    /\      /\/\    /  \  )
( /\/\/\, /\/  \, /  \/\, /    \, /    \ )
concatenate(iterable, separator, empty=None)

Concatenate multiple character art instances

The breakpoints are set as the breakpoints of the separator together with the breakpoints of the objects in iterable. If there is None, the end of the separator is used.

INPUT:

  • iterable – iterable of character art.
  • separable – character art. The separator in-between the iterable.
  • empty – an optional character art which is returned if iterable is empty

EXAMPLES:

sage: i2 = identity_matrix(2)
sage: ascii_art(i2, i2, i2, sep=ascii_art(1/x))
     1     1
[1 0]-[1 0]-[1 0]
[0 1]x[0 1]x[0 1]