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 -------
signature.asc
Description: Digital signature