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
-------
In that case, take a look at the lstlistings stuff in SageTeX for the
sagecommandline environment. There's some nice stuff there based on the
Python syntax highlighting. (Or just use the "listings" package and set
the syntax to Python.)