Skip to main content

Discrete Math with SageMath: Learn math with open-source software

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 for pretty_print().
  • latex() produces the raw code for the expression inside the parentheses. You can paste this code into a document to display the expression.
  • %display latex renders the output of commands as automatically.
  • While Python string formatting is available, the output is unreliable for rendering rich text and 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 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 until you change the display mode. The display mode is still set from the previous cell.
Revert to the default output with %display plain.