%<latex>\ProvidesPackage{sagetex}

%<python>__version__ = """

- [2010/0~~3~~/2~~5~~ v2.~~2.5~~ embedding Sage into LaTeX documents]

+ [2010/10/20 v2.3 embedding Sage into LaTeX documents]

-%<latex>\newcommand{\ST@ver}{2010/0~~3~~/2~~5~~ v2.~~2.5~~}

+%<latex>\newcommand{\ST@ver}{2010/10/20 v2.3}

Many thanks to Jason Grout for his numerous comments, suggestions, and

feedback. Thanks to Nicolas Thi\'ery for the initial code and

-contributions to the \texttt{sageexample} environment.

+contributions to the \texttt{sageexample} environment and Volker Braun

+for the \texttt{sagecommandline} environment.

\section{Copying and licenses}

\label{sec:copying-licenses}

% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z

% \changes{v2.1}{2009/05/12}{Add pausing support}

% \changes{v2.1}{2009/05/12}{Get version written to .py file}

% \changes{v2.2}{2009/06/17}{Add remote-sagetex.py script}

+% \changes{v2.3}{2010/10/20}{Add sagecommandline environment}

% \GetFileInfo{sagetex.sty}

% filename, including it into your document, and so on. In

% \autoref{sec:usage}, we will see what what we can do with \ST.

-% \subsection{Sage Command Line}

-% Yet another way to use \ST{} is as a pretty-printing command line,

-% this is provided by the |sagecommandline| environment. For example,

-% |\begin{sagecommandline}|\\

-% | sage: 1+1 # difficult|\\

-% | sage: ( x^2+2*x+1 ).factor() #@\label{square}|\\

-% |\end{sagecommandline}|

-% As you can see, you have a choice of either explicitly providing the

-% Sage output (in which case it will be turned into a doctest), or

-% leaving it up to the computer to fill in the blanks. Moreover, any

-% sage comment that starts with a ``at'' sign is escaped to \LTX. In

-% particular, you can use |\label| to mark line numbers in order to

-% |\ref|erence and |\pageref|erence them as usual. The output looks

- sage: ( x^2+2*x+1 ).factor() #@\label{square}

-% and the label is on Line~\ref{square}, Page~\pageref{square}. If you

-% prefer to typeset the output in \LTX, you can set

-% |\renewcommand{\sagecommandlinetextoutput}{False}|

-\renewcommand{\sagecommandlinetextoutput}{False}

- sage: ( a*x^2+b*x+c ).solve(x)

-\renewcommand{\sagecommandlinetextoutput}{True}

-% 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. It is recommended to

-% derive from |DefaultSageInput| and |DefaultSageOutput|, for example

-% |\lstdefinestyle{SageInput}{style=DefaultSageInput,|\\

-% | basicstyle={\color{red}}}|\\

-% |\lstdefinestyle{SageOutput}{style=DefaultSageOutput,|\\

-% | basicstyle={\color{green}}}|

-% makes things overly colorful:

-\lstdefinestyle{SageInput}{style=DefaultSageInput,basicstyle={\color{red}}}

-\lstdefinestyle{SageOutput}{style=DefaultSageOutput,basicstyle={\color{green}}}

-\lstdefinestyle{SageInput}{style=DefaultSageInput}

-\lstdefinestyle{SageOutput}{style=DefaultSageOutput}

% \label{sec:installation}

% Let's begin with a rough description of how \ST works. Naturally the

% very first step is to put |\usepackage{sagetex}| in the preamble of

% your document. When you use macros from this package and run \LTX on

-% your file, along with the usual zoo of auxiliary files, a |.sage|

-% file is written with the same basename as your document. This is a

-% Sage source file that uses the Python module from this package and

-% when you run Sage on that file, it will produce a |.sout| and a

-% |.scmd| file. That file contains \LTX code that, when you run \LTX

-% on your source file again, will pull in all the results of Sage's

+% your file, along with the usual zoo of auxiliary files, a |.sage| file

+% is written with the same basename as your document. This is a Sage

+% source file that uses the Python module from this package and when you

+% run Sage on that file, it will produce a |.sout| and a |.scmd| file.

+% The |.sout| file contains \LTX code that, when you run \LTX on your

+% source file again, will pull in all the results of Sage's computation.

% The |sagecommandline| environment additionally logs the plain sage

% commands and output furthermore in a |.scmd| file.

% \DescribeEnv{sagecommandline} This environment is similar to the

-% sageexample environment in that it allow you to include doctest-like

-% snippets in your document. The difference is that the output is

-% typeset as text, much like running Sage on the command line, using

-% the lstlisting environment. In particular, this environment provides

-% Python syntax highlighting and line numbers.

+% sageexample environment in that it allow you to use \ST as a

+% pretty-printing command line, or to include doctest-like snippets in

+% your document. The difference is that the output is typeset as text,

+% much like running Sage on the command line, using the

+% |lstlisting| environment. In particular, this environment

+% provides Python syntax highlighting and line numbers. For example,

% |\begin{sagecommandline}|\\

% | sage: factor(x^2 + 2*x + 1)|\\

% |\end{sagecommandline}|

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

+% You have a choice of either explicitly providing the Sage output (in

+% which case it will be turned into a doctest), or leaving it up to the

+% computer to fill in the blanks. Above, the output for $1+1$ was

+% provided, but the output for the |factor()| command wasn't. Moreover,

+% any Sage comment that starts with a ``at'' sign is escaped to \LTX. In

+% particular, you can use |\label| to mark line numbers in order to

+% |\ref|erence and |\pageref|erence them as usual. See the example file

+% to see this mechanism in action.

+% If you prefer to typeset the output in \LTX, you can set

+% |\renewcommand{\sagecommandlinetextoutput}{False}|

+\renewcommand{\sagecommandlinetextoutput}{False}

+ sage: ( a*x^2+b*x+c ).solve(x)

+\renewcommand{\sagecommandlinetextoutput}{True}

+% 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. It is recommended to

+% derive from |DefaultSageInput| and |DefaultSageOutput|, for example

+% |\lstdefinestyle{SageInput}{style=DefaultSageInput,|\\

+% | basicstyle={\color{red}}}|\\

+% |\lstdefinestyle{SageOutput}{style=DefaultSageOutput,|\\

+% | basicstyle={\color{green}}}|

+% makes things overly colorful:

+\lstdefinestyle{SageInput}{style=DefaultSageInput,basicstyle={\color{red}}}

+\lstdefinestyle{SageOutput}{style=DefaultSageOutput,basicstyle={\color{green}}}

+\lstdefinestyle{SageInput}{style=DefaultSageInput}

+\lstdefinestyle{SageOutput}{style=DefaultSageOutput}

% \DescribeMacro{\sagetexindent} There is one final bit to our

% verbatim-like environments: the indentation. The \ST package defines a