Hi Alex, > If I understand correctly your question, you would like to > convert arithmetical expressions directly into Latex.
I would like to convert a string into a sage-Latex-expression (in sagetex). > I don't know if it is possible to do it in Sage, but you could > always write your own function. I've written a small one that > should do the trick. [...] > sage: sarrus(matrix) > '[1 \\cdot 0 \\cdot 1 + 1 \\cdot (-1) \\cdot (-1) + 1 \\cdot 1 > \\cdot 0] - [1 \\cdot 0 \\cdot (-1) + 1 \\cdot 1 \\cdot 1 + 1 > \\cdot (-1) \ \cdot 0]' > sage: print sarrus(matrix) > [1 \cdot 0 \cdot 1 + 1 \cdot (-1) \cdot (-1) + 1 \cdot 1 \cdot 0] > - [1 \cdot 0 \cdot (-1) + 1 \cdot 1 \cdot 1 + 1 \cdot (-1) \cdot > 0] > > Does that answer your problem ? Thank you for the code (it's more elegant than my first try :) ). It doesn't work too, because the problem is that sagetex is putting the string in some kind of (typewriter-)enviroment. After some experimentation i found a possible solution is to replace "\cdot" with "$\cdot$". It doesn't look nice, but better than before. Georg > On 5 mai, 11:28, "Dr. Georg Damm" <georg.d...@web.de> wrote: > > Hi all, > > > > i've written a function to explain the rule of sarrus. Is there > > a possibility to return latex code insted of a text? I'd like > > to use something like $\sage{sarrus(A)}$ in sagetex. > > > > Thanks a lot, > > > > Georg > > > > P.S.: I expirimented with JSMathExpr from sage.misc.latex, but > > i couldn't improve the output. > > > > def sarrus(A): > > res="" > > for i in range(3): > > > > if (A[0,i]>=0): > > res+="+"+latex(A[0,i]) > > else: > > res+="+("+latex(A[0,i])+")" > > if (A[1,(i+1)%3]>=0): > > res+="*"+latex(A[1,(i+1)%3]) > > else: > > res+="*("+latex(A[1,(i+1)%3])+")" > > if (A[2,(i+2)%3]>=0): > > res+="*"+latex(A[2,(i+2)%3]) > > else: > > res+="*("+latex(A[2,(i+2)%3])+")" > > > > for i in range(2,5): > > if (A[0,i%3]>=0): > > res+="-"+latex(A[0,i%3]) > > else: > > res+="-("+latex(A[0,i%3])+")" > > if (A[1,(i-1)%3] >= 0): > > res+="*"+latex(A[1,(i-1)%3]) > > else: > > res+="*("+latex(A[1,(i-1)%3])+")" > > if (A[2,(i-2)%3]>=0): > > res+="*"+latex(A[2,(i-2)%3]) > > else: > > res+="*("+latex(A[2,(i-2)%3])+")" > > return res > > > > -- > > 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 For > > more options, visit this group > > athttp://groups.google.com/group/sage-support > > URL:http://www.sagemath.org > -- 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 For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org