The Sage rich representation system requires a special container class to hold the data for each type of rich output. They all inherit from OutputBase, though a more typical example is OutputPlainText. Some output classes consist of more than one data buffer, for example jmol or certain animation formats. The output class is independent of user preferences and of the display backend.
The display backends can define derived classes to attach backend-specific display functionality to, for example how to launch a viewer. But they must not change how the output container is created. To enforce this, the Sage _rich_repr_ magic method will only ever see the output class defined here. The display manager will promote it to a backend-specific subclass if necessary prior to displaying it.
To create new types of output, you must create your own subclass of OutputBase and register it in sage.repl.rich_output.output_catalog.
Warning
All rich output data in sublasses of OutputBase must be contained in OutputBuffer instances. You must never reference any files on the local file system, as there is no guarantee that the notebook server and the worker process are on the same computer. Or even share a common file system.
Bases: sage.repl.rich_output.output_basic.OutputBase
ASCII Art Output
INPUT:
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputAsciiArt
sage: OutputAsciiArt(':-}')
OutputAsciiArt container
Construct a sample ascii art output container
This static method is meant for doctests, so they can easily construt an example.
OUTPUT:
An instance of OutputAsciiArt.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputAsciiArt
sage: OutputAsciiArt.example()
OutputAsciiArt container
sage: OutputAsciiArt.example().ascii_art.get()
'[ * * * * ]\n[ ** ** * * * * * * ]\n[ ***, * , * , **, ** , *, * , * , * ]'
Write the data to stdout.
This is just a convenience method to help with debugging.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputAsciiArt
sage: ascii_art = OutputAsciiArt.example()
sage: ascii_art.print_to_stdout()
[ * * * * ]
[ ** ** * * * * * * ]
[ ***, * , * , **, ** , *, * , * , * ]
Bases: sage.structure.sage_object.SageObject
Base class for all rich output containers.
Construct a sample instance
This static method is meant for doctests, so they can easily construt an example.
OUTPUT:
An instance of the OutputBase subclass.
EXAMPLES:
sage: from sage.repl.rich_output.output_basic import OutputBase
sage: OutputBase.example()
Traceback (most recent call last):
...
NotImplementedError: derived classes must implement this class method
Bases: sage.repl.rich_output.output_basic.OutputBase
LaTeX Output
Note
The LaTeX commands will only use a subset of LaTeX that can be displayed by MathJax.
INPUT:
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputLatex
sage: OutputLatex('<html><script type="math/tex; mode=display">1</script></html>')
OutputLatex container
Return the LaTeX code for a display equation
OUTPUT:
String.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputLatex
sage: rich_output = OutputLatex('1')
sage: rich_output.latex
buffer containing 1 bytes
sage: rich_output.latex.get()
'1'
sage: rich_output.display_equation()
'\\begin{equation}\n1\n\\end{equation}'
Construct a sample LaTeX output container
This static method is meant for doctests, so they can easily construt an example.
OUTPUT:
An instance of OutputLatex.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputLatex
sage: OutputLatex.example()
OutputLatex container
sage: OutputLatex.example().latex.get()
'\\newcommand{\\Bold}[1]{\\mathbf{#1}}\\int \\sin\\left(x\\right)\\,{d x}'
Return the LaTeX code for an inline equation
OUTPUT:
String.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputLatex
sage: rich_output = OutputLatex('1')
sage: rich_output.latex
buffer containing 1 bytes
sage: rich_output.latex.get()
'1'
sage: rich_output.inline_equation()
'\\begin{math}\n1\n\\end{math}'
Return the LaTeX with a surrounding MathJax HTML code.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputLatex
sage: rich_output = OutputLatex('1')
sage: rich_output.latex
buffer containing 1 bytes
sage: rich_output.latex.get()
'1'
sage: rich_output.mathjax()
'<html><script type="math/tex; mode=display">1</script></html>'
Write the data to stdout.
This is just a convenience method to help with debugging.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputLatex
sage: rich_output = OutputLatex.example()
sage: rich_output.print_to_stdout()
\newcommand{\Bold}[1]{\mathbf{#1}}\int \sin\left(x\right)\,{d x}
Bases: sage.repl.rich_output.output_basic.OutputBase
Plain Text Output
INPUT:
This should always be exactly the same as the (non-rich) output from the _repr_ method. Every backend object must support plain text output as fallback.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputPlainText
sage: OutputPlainText('foo')
OutputPlainText container
Construct a sample plain text output container
This static method is meant for doctests, so they can easily construt an example.
OUTPUT:
An instance of OutputPlainText.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputPlainText
sage: OutputPlainText.example()
OutputPlainText container
sage: OutputPlainText.example().text.get()
'Example plain text output'
Write the data to stdout.
This is just a convenience method to help with debugging.
EXAMPLES:
sage: from sage.repl.rich_output.output_catalog import OutputPlainText
sage: plain_text = OutputPlainText.example()
sage: plain_text.print_to_stdout()
Example plain text output