Open vbraun opened 9 years ago
PS: ascii art output would look like this
sage: %display ascii_art
sage: pi.n(100), CartanMatrix("E8~").dynkin_diagram()
( O 2 )
( | )
( | )
( O---O---O---O---O---O---O---O )
( 1 3 4 5 6 7 8 0 )
( 3.1415926535897932384626433833, E8~ )
Related: #15565.
For the record, this is the decision Axiom (maybe better known here as FriCAS) made a few decades ago, output is ascii-art. The downside is, of course, that you cannot copy output into the clipboard and reuse it as input. However, especially for symbolic expressions involving sums, products, powers, fractions, the ascii-art is a great convenience!
Back to sage, as mentioned by Marc, also (small) matrices are always typeset as ascii-art, similar to Dynkin diagrams. Are there any others?
Note that we have sage_input
(though objects with fancy representation need to explictly support it):
sage: polytopes.hypercube(3)
A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices
sage: sage_input(_)
Polyhedron(base_ring=ZZ, vertices=[(-1, -1, -1), (-1, -1, 1), (-1, 1, -1), (-1, 1, 1), (1, -1, -1), (1, -1, 1), (1, 1, -1), (1, 1, 1)])
am I right in guessing that _repr_
contains ascii-art if it returns a string which contains a newline (i.e., \n
)?
If so, it should be quite possible to collect at least a few "bad guys"...
The plain displayhook actually has support for ascii-art matrices
sage: %display plain
sage: pi.n(100), identity_matrix(2)
(
[1 0]
3.1415926535897932384626433833, [0 1]
)
but its hardcoded to apply to matrices only. The ascii art output is much more flexible.
There are probably multiple places where
_repr_()
returns ascii art and not a string that can be composed with other strings. That then leads to issues likeThe solution should be to move ascii art to the magic
_ascii_art_
method.Unfortunately, the IPython commandline defaults to plain text output. So you either have to switch
or override
_rich_repr_
to make ascii art the default for your object. Perhaps the default display preference on the commandline should be changed to ascii art.Component: user interface
Issue created by migration from https://trac.sagemath.org/ticket/18328