Ask Your Question

Revision history [back]

Yes, in interactive Python sessions, output uses displayhook instead of repr:

sage: A=matrix([[1,2],[3,4]])
sage: u=[A,A]
sage: repr(u)
'[[1 2]\n[3 4], [1 2]\n[3 4]]'
sage: import sys
sage: sys.displayhook(u)
[
[1 2]  [1 2]
[3 4], [3 4]
]

Sage defines it's own module sage.misc.displayhook. Imho that's a dead end, because math formatting is very complex, and the right tool is LaTeX, very well integrated in Sage and Sage Notebook. I suggest you write a method _latex_(self) for your objects, then lists of these objects will be correctly formatted by LaTeX.

click to hide/show revision 2
precise explication added

Yes, in interactive Python sessions, output uses displayhook instead of repr:

sage: A=matrix([[1,2],[3,4]])
sage: u=[A,A]
sage: repr(u)
'[[1 2]\n[3 4], [1 2]\n[3 4]]'
sage: import sys
sage: sys.displayhook(u)
[
[1 2]  [1 2]
[3 4], [3 4]
]

Sage defines it's own module sage.misc.displayhook. Imho that's a dead end, because math formatting is very complex, and the right tool is LaTeX, very well integrated in Sage and Sage Notebook. I suggest you write a method _latex_(self) for your objects, then lists of these objects will be correctly formatted by LaTeX.LaTeX. Because the string

'[ repr(A), repr(B) ]'

is not a valid representation for [A,B] if there are newlines inside repr(A) and repr(B), while

\left[ latex(A), latex(B) \right]

is always a valid LaTeX description of [A,B].

Yes, in interactive Python sessions, output uses displayhook instead of repr:

sage: A=matrix([[1,2],[3,4]])
sage: u=[A,A]
sage: repr(u)
'[[1 2]\n[3 4], [1 2]\n[3 4]]'
sage: import sys
sage: sys.displayhook(u)
[
[1 2]  [1 2]
[3 4], [3 4]
]

Sage defines it's own module sage.misc.displayhook. Imho that's a dead end, because math formatting is very complex, and the right tool is LaTeX, very well integrated in Sage and Sage Notebook. I suggest you write a method _latex_(self) for your objects, then lists of these objects will be correctly formatted by LaTeX. Because the The string

'[ repr(A), repr(B) ]'

is not a valid representation for [A,B] if there are newlines inside repr(A) and repr(B), while

\left[ latex(A), latex(B) \right]

is always a valid LaTeX description of [A,B].

Yes, in interactive Python sessions, output uses displayhook instead of repr:

sage: A=matrix([[1,2],[3,4]])
sage: u=[A,A]
sage: repr(u)
'[[1 2]\n[3 4], [1 2]\n[3 4]]'
sage: import sys
sage: sys.displayhook(u)
[
[1 2]  [1 2]
[3 4], [3 4]
]

Sage defines it's own module sage.misc.displayhook. Imho that's a dead end, because math formatting is very complex, and the right tool is LaTeX, very well integrated in Sage and Sage Notebook. I suggest you write a method _latex_(self) for your objects, then lists of these objects will be correctly formatted by LaTeX. The string

'[ repr(A), '[' + repr(A) + ',' + repr(B) ]'
+ ']'

is not a valid representation for [A,B] if there are newlines inside repr(A) and repr(B), while

\left[ latex(A), '\left[' + latex(A) + ',' + latex(B) \right]
+ '\right]'

is always a valid LaTeX description of [A,B].