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 at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to