Hi Dan my intention is to generate tests using sagetex and sage. So I will 
have something like

m = 'undefined' if denom==0 else (y2-y1)/(x2-x1)

.....

then print out m at some point. So $\sage{m}$ does not work is denom==0 but 
\sagestr{m} doesn't seem to work if denom<>0.
Any suggestion?

On Saturday, December 15, 2012 10:09:20 AM UTC-8, Dan Drake wrote:
>
> On Sat, 15 Dec 2012 at 02:45AM -0800, pong wrote: 
> > I am having the same trouble as John. Would you expand a little bit on 
> your 
> > solution: 
> > 
> > for example 
> > $\sage{'Hello'}$ 
> > causes an error. Where should I put the 'r' as suggested in your post (I 
> > think stands for raw string)? I tried several combination but nothing 
> seems 
> > to work. 
>
> It causes an error because the \sage{} macro runs Sage's latex() 
> function on its argument, which in this case produces "\verb|Hello|". 
> Then TeX gets unhappy because of the verbatim text inside a math 
> environment. 
>
> If you just want the string 'Hello' inserted into your document, use 
> \sagestr{}. Or, don't surround \sage{} with dollar signs. 
>
> > > SAGE should not read Python escape codes inside $'s. As you've 
> > > noticed from the error message, SAGE doesn't even know it's still 
> > > doing it. It thinks it's parsing LaTeX. 
>
> There is no (easy/reasonable) way for SageTeX to detect whether \sage{} 
> was called within a math environment, and in any case, altering Sage's 
> behavior with respect to Python string conventions would require a lot 
> of work in the preparser that (1) would be difficult, and (2) represent 
> a large deviation from standard Python behavior that almost no one would 
> think is reasonable. (That's what I think, at any rate...) 
>
> Also, as was pointed out, you can use raw strings to avoid that 
> behavior. TeX is completely oblivious to the difference between 
> \sage{r"\nabla"} and \sage{"\nabla"}, so you can always use the former 
> to get your intended behavior. 
>
> Dan 
>
> -- 
> ---  Dan Drake 
> -----  http://math.pugetsound.edu/~ddrake 
> ------- 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to