Base Class for Character-Based Art#

This is the common base class for sage.typeset.ascii_art.AsciiArt and sage.typeset.unicode_art.UnicodeArt. They implement simple graphics by placing characters on a rectangular grid, in other words, using monospace fonts. The difference is that one is restricted to 7-bit ascii, the other uses all unicode code points.

class sage.typeset.character_art.CharacterArt(lines=[], breakpoints=[], baseline=None)[source]#

Bases: SageObject

Abstract base class for character art

INPUT:

  • lines – the list of lines of the representation of the character art object

  • breakpoints – the list of points where the representation can be split

  • baseline – the reference line (from the bottom)

Instead of just integers, breakpoints may also contain tuples consisting of an offset and the breakpoints of a nested substring at that offset. This is used to prioritize the breakpoints, as line breaks inside the substring will be avoided if possible.

EXAMPLES:

sage: i = var('i')                                                          # needs sage.symbolic
sage: ascii_art(sum(pi^i/factorial(i)*x^i, i, 0, oo))                       # needs sage.symbolic
 pi*x
e
>>> from sage.all import *
>>> i = var('i')                                                          # needs sage.symbolic
>>> ascii_art(sum(pi**i/factorial(i)*x**i, i, Integer(0), oo))                       # needs sage.symbolic
 pi*x
e
classmethod empty()[source]#

Return the empty character art object

EXAMPLES:

sage: from sage.typeset.ascii_art import AsciiArt
sage: AsciiArt.empty()
>>> from sage.all import *
>>> from sage.typeset.ascii_art import AsciiArt
>>> AsciiArt.empty()
get_baseline()[source]#

Return the line where the baseline is, for example:

    5      4
14*x  + 5*x

the baseline has at line \(0\) and

{ o       }
{  \  : 4 }
{   o     }

has at line \(1\).

get_breakpoints()[source]#

Return an iterator of breakpoints where the object can be split.

This method is deprecated, as its output is an implementation detail. The mere breakpoints of a character art element do not reflect the best way to split it if nested structures are involved. For details, see Issue #29204.

For example the expression:

   5    4
14x + 5x

can be split on position 4 (on the +).

EXAMPLES:

sage: from sage.typeset.ascii_art import AsciiArt
sage: p3 = AsciiArt([" * ", "***"])
sage: p5 = AsciiArt(["  *  ", " * * ", "*****"])
sage: aa = ascii_art([p3, p5])
sage: aa.get_breakpoints()
doctest:...: DeprecationWarning: get_breakpoints() is deprecated
See https://github.com/sagemath/sage/issues/29204 for details.
[6]
>>> from sage.all import *
>>> from sage.typeset.ascii_art import AsciiArt
>>> p3 = AsciiArt([" * ", "***"])
>>> p5 = AsciiArt(["  *  ", " * * ", "*****"])
>>> aa = ascii_art([p3, p5])
>>> aa.get_breakpoints()
doctest:...: DeprecationWarning: get_breakpoints() is deprecated
See https://github.com/sagemath/sage/issues/29204 for details.
[6]
height()[source]#

Return the height of the ASCII art object.

OUTPUT:

Integer. The number of lines.

split(pos)[source]#

Split the representation at the position pos.

EXAMPLES:

sage: from sage.typeset.ascii_art import AsciiArt
sage: p3 = AsciiArt([" * ", "***"])
sage: p5 = AsciiArt(["  *  ", " * * ", "*****"])
sage: aa = ascii_art([p3, p5])
sage: a,b= aa.split(6)
sage: a
[
[  *
[ ***,
sage: b
   *   ]
  * *  ]
 ***** ]
>>> from sage.all import *
>>> from sage.typeset.ascii_art import AsciiArt
>>> p3 = AsciiArt([" * ", "***"])
>>> p5 = AsciiArt(["  *  ", " * * ", "*****"])
>>> aa = ascii_art([p3, p5])
>>> a,b= aa.split(Integer(6))
>>> a
[
[  *
[ ***,
>>> b
   *   ]
  * *  ]
 ***** ]
width()[source]#

Return the length (width) of the ASCII art object.

OUTPUT:

Integer. The number of characters in each line.