1

I am preparing a class on Sage, and i want the following code on my document.

\documentclass{article}
\usepackage{sagetex}

\begin{document}

\begin{sagecommandline}
sage: for i in range(0,4):
....:     i^2
\end{sagecommandline}

\end{document}

However, i want it to display the output as it does in a Sage worksheet.

1

Working with your code, I'd try something like this:

\documentclass{article}
\usepackage{sagetex}
\lstdefinestyle{SageInput}{style=DefaultSageInput, numbers=none}
\begin{document}
\begin{sagecommandline}
sage: for i in range(0,4):
....:     i^2
\end{sagecommandline}
\begin{sagesilent}
output = r""
for i in range(0,4):
    output += r"\texttt{%s}\\"%(i^2)  
\end{sagesilent}
\sagestr{output}
\end{document}

The output running in Cocalc is: enter image description here

The code numbers=none turns off the line numbers, if that's something you wanted.

You might also be interested to know that my answer to the question Questions about including source code in a TeX file mentions that one of the developers of SAGE has posted a LaTeX file that he uses in typesetting SAGE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.