Commits

Anonymous committed 3e5d53b

add some sagecommandline stuff to the example file

Comments (0)

Files changed (1)

  \draw[smooth, red] plot file {example-tikz2.table};
 \end{tikzpicture}
 
+\section{The \texttt{sagecommandline} environment}
 
+When writing a \TeX{} document about Sage, you may want to show some
+examples of commands and their output. But naturally, you are lazy and
+don't want to cut and paste the output into your document. ``Why should
+I have to do anything? Why can't Sage and \TeX{} cooperate and do it for
+me?'' you may cry. Well, they \emph{can} cooperate:
+
+\begin{sagecommandline}
+  sage: 1+1
+  sage: is_prime(57)
+\end{sagecommandline}
+
+Note that the output of the commands is not included in the source file,
+but are included in the typeset output.
+
+Because of the way the environment is implemented, not everything is
+exactly like using Sage in a terminal: the two commands below would
+produce some output, but don't here:
+
+\begin{sagecommandline}
+  sage: x = 2010; len(x.divisors())
+  sage: print 'Hola, mundo!'
+\end{sagecommandline}
+
+The difference lies in the Python distinction between statements and
+expressions.
+
+One nice thing is that you can set labels by using an @ sign:
+
+\begin{sagecommandline}
+  sage: l = matrix([[1,0,0],[3/5,1,0],[-2/5,-2,1]])
+  sage: d = diagonal_matrix([15, -1, 4]) #@\label{diagonal}
+  sage: u = matrix([[1,0,1/3],[0,1,2],[0,0,1]])
+  sage: l*d*u   # this is a comment
+\end{sagecommandline}
+
+And then refer to that label: it was on line \ref{diagonal}, which is on
+page \pageref{diagonal}.
+
+You can also typeset the output:
+
+\renewcommand{\sagecommandlinetextoutput}{False}
+
+\begin{sagecommandline}
+  sage: l*d*u
+  sage: x = var('x')
+  sage: (1-cos(x)^2).trig_simplify()
+\end{sagecommandline}
+
+\renewcommand{\sagecommandlinetextoutput}{True}
+
+The Sage input and output is typeset using the \texttt{listings} package
+with the styles \texttt{SageInput} and \texttt{SageOutput},
+respectively. If you don't like the defaults you can change them. It is
+recommended to derive from \texttt{DefaultSageInput} and
+\texttt{DefaultSageOutput}, for example\ldots
+\lstdefinestyle{SageInput}{style=DefaultSageInput,basicstyle={\color{red}}}
+\lstdefinestyle{SageOutput}{style=DefaultSageOutput,basicstyle={\color{green}}}
+makes things overly colorful:
+\begin{sagecommandline}
+  sage: pi.n(100)
+\end{sagecommandline}
+\lstdefinestyle{SageInput}{style=DefaultSageInput}
+\lstdefinestyle{SageOutput}{style=DefaultSageOutput}
 
 \end{document}