1 | initial version |

Is `sagecommandline`

what you are looking for?

I found it by searching the sagetex github repo for "highlighting":

- https://github.com/sagemath/sagetex/search?q=highlighting

Try this (from the documentation).

```
\begin{sagecommandline}
sage: 1+1
2
sage: factor(x^2 + 2*x + 1)
\end{sagecommandline}
```

2 | No.2 Revision |

Is `sagecommandline`

what you are looking for?

I found it by searching the sagetex github repo for "highlighting":

- https://github.com/sagemath/sagetex/search?q=highlighting

Try this (from the documentation).

```
\begin{sagecommandline}
sage: 1+1
2
sage: factor(x^2 + 2*x + 1)
(x + 1)^2
\end{sagecommandline}
```

For function definitions or loops, use the continuation prompt `....:`

as follows:

```
\begin{sagecommandline}
sage: def square(x):
....: return x * x
....:
sage: square(12)
144
sage: first_few_squares = []
sage: for n in range(4):
....: first_few_squares.append(square(n))
....:
sage: first_few_squares
[0, 1, 4, 9]
\end{sagecommandline}
```

To get rid of the output, change the value of `sagecommandlinetextoutput`

:

```
\renewcommand{\sagecommandlinetextoutput}{False}
```

The documentation of SageTeX and its example file have a lot of information.

One comment in the example file is:

The Sage input and output is typeset using the

`listings`

package with the styles`SageInput`

and`SageOutput`

, respectively. If you don't like the defaults you can change them.

and there is a recommendation on how to change the defaults if you want to.

Another wonderful feature (which justifies including the `sage:`

prompt) is

You can include output, but it will be ignored. This is useful for doctesting, as all the

`sagecommandline`

environment things get put into the`_doctest.sage`

file.

3 | No.3 Revision |

Is `sagecommandline`

what you are looking for?

I found it by searching the sagetex github repo for "highlighting":

- https://github.com/sagemath/sagetex/search?q=highlighting

Try this (from the documentation).

```
\begin{sagecommandline}
sage: 1+1
2
sage: factor(x^2 + 2*x + 1)
(x + 1)^2
\end{sagecommandline}
```

For function definitions or loops, use the continuation prompt `....:`

as follows:

```
\begin{sagecommandline}
sage: def square(x):
....: return x * x
....:
sage: square(12)
144
sage: first_few_squares = []
sage: for n in range(4):
....: first_few_squares.append(square(n))
....:
sage: first_few_squares
[0, 1, 4, 9]
\end{sagecommandline}
```

To get rid of the output, change the value of `sagecommandlinetextoutput`

:

```
\renewcommand{\sagecommandlinetextoutput}{False}
```

The documentation of SageTeX and its example file have a lot of information.

One comment in the example file is:

The Sage input and output is typeset using the

`listings`

package with the styles`SageInput`

and`SageOutput`

, respectively. If you don't like the defaults you can change them.

and there is a recommendation on how to change the defaults if you want to.

Another wonderful feature (which justifies including the `sage:`

prompt) is

You can include output, but it will be ignored. This is useful for doctesting, as all the

`sagecommandline`

environment things get put into the`_doctest.sage`

file.

The SageTeX documentation and example file are worth reading and studying!

If you have Sage installed and if `/path/to/sagedir`

is the directory
where it is installed, open a terminal and run the following:

```
SAGE_ROOT='/path/to/sagedir'
cd $SAGE_ROOT/local/share/texmf/tex/latex/sagetex
export TEXINPUTS="$SAGE_ROOT/local/share/texmf//:"
pdflatex example.tex
sage example.sagetex.sage
pdflatex example.tex
open example.pdf
```

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.