I think you should put "sage:" in front of all complete commands and "..." in front of continuation lines. I was making multi-line cycles this way. Triple quotes may conflict with the way how SageTeX produces its files. Did you try triple single quotes? ( ' + ' + ' instead of " + " + ")
Andrey On Oct 25, 9:10 am, javier <vengor...@gmail.com> wrote: > Hi all, > > 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} > class PowerSetRingElement(RingElement): > """ > Class for defining elements of a power set ring > """ > def __init__(self, Y, parent=None): > try: > YY = Set(Y) > if YY.issubset(parent._set): > self._subset = YY > self._parent = parent > RingElement.__init__(self, parent) > else: > raise TypeError, "\percent{}s must be a subset of > \percent{}s"(Y, parent._set) > except: > raise NotImplementedError > > def _repr_(self): > return "\percent{}s"\percent{}self._subset > > def _add_(self, other): > return > self._parent(self._subset.symmetric_difference(other._subset)) > > def _mul_(self, other): > return self._parent(self._subset.intersection(other._subset)) > \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 """ > > 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. > > 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): > def __init__(self, Y, parent=None): > try: > YY = Set(Y) > if YY.issubset(parent._set): > self._subset = YY > self._parent = parent > RingElement.__init__(self, parent) > else: > raise TypeError, "%s must be a subset of %s"(Y, > parent._set) > except: > raise NotImplementedError > \end{sagecommandline} > > then I get > > **** Error in Sage code on line 312 of 3201-sage.tex! Traceback > follows. > Traceback (most recent call last): > File "3201-sage.sagetex.py", line 104, in <module> > """, globals(), locals(), True) > File "/Applications/sage/local/lib/python2.6/site-packages/ > sagetex.py", line 203, in commandline > exec current_statement in globals, locals > File "<string>", line 1 > class PowerSetRingElement(RingElement): > ^ > SyntaxError: unexpected EOF while parsing > > Any ideas? > > Cheers, > Javier -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org