Factory for Character-Based Art¶
- class sage.typeset.character_art_factory.CharacterArtFactory(art_type, string_type, magic_method_name, parenthesis, square_bracet, curly_brace)[source]¶
Bases:
SageObject
Abstract base class for character art factory.
This class is the common implementation behind
ascii_art()
andunicode_art()
.INPUT:
art_type
– type of the character art (i.e. a subclass ofCharacterArt
)string_type
– type of strings (the lines in the character art, e.g.str
orunicode
)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'>
>>> from sage.all import * >>> from sage.typeset.ascii_art import _ascii_art_factory as factory >>> type(factory) <class 'sage.typeset.character_art_factory.CharacterArtFactory'>
- build(obj, baseline=None)[source]¶
Construct a character art representation.
INPUT:
obj
– anything; the object whose ascii art representation we wantbaseline
– (optional) the baseline of the object
OUTPUT: character art object
EXAMPLES:
sage: result = ascii_art(integral(exp(x+x^2)/(x+1), x)) # needs sage.symbolic ... sage: result # needs sage.symbolic / | | 2 | x + x | e | ------- dx | x + 1 | /
>>> from sage.all import * >>> result = ascii_art(integral(exp(x+x**Integer(2))/(x+Integer(1)), x)) # needs sage.symbolic ... >>> result # needs sage.symbolic / | | 2 | x + x | e | ------- dx | x + 1 | /
- build_container(content, left_border, right_border, baseline=0)[source]¶
Return character art for a container.
INPUT:
content
–CharacterArt
; the content of the container, usually comma-separated entriesleft_border
–CompoundSymbol
; the left border of the containerright_border
–CompoundSymbol
; the right border of the containerbaseline
– (default: 0) the baseline of the object
- build_empty()[source]¶
Return the empty character art object.
OUTPUT: character art instance
EXAMPLES:
sage: from sage.typeset.ascii_art import _ascii_art_factory as factory sage: str(factory.build_empty()) ''
>>> from sage.all import * >>> from sage.typeset.ascii_art import _ascii_art_factory as factory >>> str(factory.build_empty()) ''
- build_from_magic_method(obj, baseline=None)[source]¶
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 # needs sage.modules [1 0] [0 1] sage: type(out) # needs sage.modules <class 'sage.typeset.ascii_art.AsciiArt'>
>>> from sage.all import * >>> from sage.typeset.ascii_art import _ascii_art_factory as factory >>> out = factory.build_from_magic_method(identity_matrix(Integer(2))); out # needs sage.modules [1 0] [0 1] >>> type(out) # needs sage.modules <class 'sage.typeset.ascii_art.AsciiArt'>
- build_from_string(obj, baseline=0)[source]¶
Return the character art object created from splitting the object’s string representation.
INPUT:
obj
– utf-8 encoded byte string or unicodebaseline
– (default: 0) the baseline of the object
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'>
>>> from sage.all import * >>> from sage.typeset.ascii_art import _ascii_art_factory as factory >>> out = factory.build_from_string('a\nbb\nccc') >>> out + out + out a a a bb bb bb ccccccccc >>> type(out) <class 'sage.typeset.ascii_art.AsciiArt'>
- concatenate(iterable, separator, empty=None, baseline=0, nested=False)[source]¶
Concatenate multiple character art instances.
The breakpoints are set as the breakpoints of the
separator
together with the breakpoints of the objects initerable
. If there isNone
, the end of the separator is used.INPUT:
iterable
– iterable of character artseparable
– character art; the separator in-between the iterableempty
– an optional character art which is returned ifiterable
is emptybaseline
– (default: 0) the baseline of the objectnested
– boolean (default:False
); ifTrue
, each of the character art objects is treated as a nested element, so that line breaks at the separator are preferred over line breaks inside the character art objects
EXAMPLES:
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]
>>> from sage.all import * >>> i2 = identity_matrix(Integer(2)) # needs sage.modules >>> ascii_art(i2, i2, i2, sep=ascii_art(Integer(1)/x)) # needs sage.modules sage.symbolic 1 1 [1 0]-[1 0]-[1 0] [0 1]x[0 1]x[0 1]
- parse_keywords(kwds)[source]¶
Parse the keyword input given by the dict
kwds
.INPUT:
kwds
– dictionary
OUTPUT:
A triple:
the separator
the baseline
the baseline of the separator
Warning
The input is a dict, not a list of keyword arguments.
Note
This will remove
sep
/separator
andbaseline
fromkwds
if they are specified.