sage: factor(x^2 + 2*x + 1)

-If you want to see the plain-text output as well as the typeset

-output, renew the \texttt{sageexampleincludetextoutput} variable to

+If you want to see the plain-text output as well as the typeset output,

+renew the \texttt{sageexampleincludetextoutput} command to True:

\renewcommand{\sageexampleincludetextoutput}{True}

+% fiddle with spacing to demonstrate the kind of thing mentioned in the

+When this environment is near the bottom of the page, it may look like

+the page number is the output of a command, when in fact the real output

+is on the next page. If the output of a command below looks like

+\thepage, don't worry, that's just the page number.

sage: factor(x^2 + 2*x + 1)

-Multiline statements are support, as are triple-quoted strings

+Multiline statements are supported, as are triple-quoted strings

delimited by single quotes:

\renewcommand{\sageexampleincludetextoutput}{False}

1/5*x^5 - 1/4*x^4 + 1/3*x^3 + x + 1

+Note that the ``$f$ called with\ldots'' stuff doesn't get typeset, since

+when running Sage on \texttt{example.sage}, that gets printed to the

When typesetting your document, the validity of the outputs is not

-checked (go ahead and try changing something above) but it should be

-possible to run the usual Sage doctest mechanism on the generated

-\texttt{.sage} file---or perhaps the \texttt{.py} file. Running

-doctests on files outside the main Sage library does not always work,

-so contact sage-support if you run into troubles.

+checked. In fact, the provided outputs are completely ignored:

+\renewcommand{\sageexampleincludetextoutput}{True}

+\renewcommand{\sageexampleincludetextoutput}{False}

+\ldots but it should be possible to run the usual Sage doctest mechanism

+on the generated \texttt{.sage} file---or perhaps the \texttt{.py} file.

+Running doctests on files outside the main Sage library does not always

+work, so contact sage-support if you run into troubles.

Some more examples. This environment is implemented a little bit

-differently than the other environments, so it's good to make sure

-that definitions are preserved across multiple uses:

+differently than the other environments, so it's good to make sure that

+definitions are preserved across multiple uses. This will correctly

+define $a$, but not print its output because the statement is made up of

+a sequence of expressions.

-After that, Sage should remember that $a = \sage{a}$, and be able to

-use that in future \texttt{sageexample} blocks:

+After that, Sage should remember that $a = \sage{a}$ and be able to use

+that in future \texttt{sageexample} blocks:

- 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + 5*x + 1~~ ~~

+ 1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + 5*x + 1