Section 1.6 Display Values
Sage provides multiple ways to display values on the screen. The simplest way is to type the value into a cell, and Sage will display it. Sage also offers functions to format and display output in different styles.
Sage automatically displays the value of the last line in a cell unless a specific function is used for output. Here are some key functions for displaying values:
print()
displays the value of the expression inside the parentheses as plain text.pretty_print()
displays rich text as typeset LaTeX output.show()
is an alias forpretty_print()
and provides additional functionality for graphics.latex()
returns the raw LaTeX code for the given expression, which then can be used in LaTeX documents.%display latex
enables automatic rendering of all output in LaTeX format.- While Python string formatting is available and can be used, it may not reliably render rich text or LaTeX expressions due to compatibility issues.
Let’s explore these display methods in action.
Typing a string directly into a Sage cell displays it with quotes.
Using
print()
removes the quotes.The
show()
function formats mathematical expressions for better readability.To display multiple values in a single cell, use
show()
for each one.The
latex()
function returns the raw LaTeX code for an expression.In Jupyter notebooks or SageMathCell, you can set the display mode to LaTeX using
%display latex
.Once set, all expressions onward will continue to be rendered in LaTeX format until the display mode is changed.
To return to the default output format, use
%display plain
.