On Tue, 25 Oct 2011 at 08:10AM -0700, javier wrote:
> I am trying to add some Sage examples to my lecture notes for a course
> in Commutative Algebra. In particular want to include an example on
> how to define the power set ring in sage. I would like to list some
> big chunks of sage code with nice colorization and all, so I was
> trying to use the `sagecommandline` environment. While this works for
> simple one-liners, I get some problems using it for classes. Here is
> some minimal example that goes wrong:
> 
>     \begin{sagecommandline}
[snip]
>     \end{sagecommandline}
> 
> Now here I face several problems. First of all, sagetex seems to raise
> syntax errors whenever the code inside a sagecommandline environment
> contains strings with triple quotes """

You can't use """ triple quotes because in the generated .sage file,
SageTeX uses """ to bundle up everything you put into the
sagecommandline environment. You can use ''' triple quotes with no
trouble.

By the way, why aren't you using the sageblock environment? That
typesets the output and allows you to use """ triple quotes. Nothing
will get written to the doctest file, and you don't get "sage:" prompts
prepended -- but who actually types in real class definitions at a
prompt?

> Now, if I remove the docstring, then sage runs just fine on the
> sagetex file, but (after re-running latex) nothing shows up on the
> final pdf.

This is somehow related to the way that sagecommandline is piecing
together the string it gets from LaTeX into chunks that it can hand to
Sage for processing. The class definition gets evaluated, but because
it's a compound statement, nothing is handed back to LaTeX to typeset.


> If I try to include the "sage" words at the beginning, as if I typed
> it in the command line
> 
>       \begin{sagecommandline}
>       sage: class PowerSetRingElement(RingElement):
[snip]
>     \end{sagecommandline}
> 
> then I get
> 
[snip]
>   File "<string>", line 1
>      class PowerSetRingElement(RingElement):
>                                            ^
>  SyntaxError: unexpected EOF while parsing

This is also related to the class definition -- it's a compound
statement, but only the first line gets handed to Python.

This stuff really should get sorted out, and I've been meaning to do it
for a while -- but for now, if sageblock isn't enough, the sageexample
environment seems to work better for what you want. Try something like
this:

\begin{sageexample}
sage: class PowerSetRingElement(RingElement):
...       def __init__(self, Y, parent=None):
...           blah
...           blah
\end{sageexample}

That typesets the definition correctly.

Regards,

Dan

--
---  Dan Drake
-----  http://mathsci.kaist.ac.kr/~drake
-------

Attachment: signature.asc
Description: Digital signature

Reply via email to