Section 1.2 Display Values
Sage offers various 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 has functions that display values in different formats.
print()
displays the value of the expression inside the parentheses on the screen.pretty_print()
displays rich text.show()
is an alias forpretty_print()
.latex()
produces the raw LaTeX code for the expression inside the parentheses. You can paste this code into a LaTeX document to display the expression.%display latex
renders the output of commands as LaTeX automatically.- While Python string formatting is available, the output is unreliable for rendering rich text and LaTeX due to compatibility issues.
Sage will display the value of the last line of code in a cell.
print()
outputs a similar result without the quotes.View mathematical notation with rich text.
If we want to display values from multiple lines of code, we can use multiple functions to display the values.
Obtain raw LaTeX code for an expression.
If you are working in a Jupyter notebook or SageMathCell,
%display latex
sets the display mode.The expressions will continue to render as LaTeX until you change the display mode. The display mode is still set from the previous cell.
Revert to the default output with
%display plain
.