Ask Your Question

Revision history [back]

You could define a function to produce a latex array (or tabular):

def matrix_array(L,ncols):
    nl = '\n'
    s = nl + r'\begin{array}{' + ('c' * ncols) + r'}' + nl
    for k in xrange(len(L)):
        if k%ncols != 0: s += '&' + nl
        s += str(latex(L[k])) + nl
        if ((k+1)%ncols == 0) or (k == len(L)):
            s += r'\\' + nl
    s += r'\end{array}' + nl
    return LatexExpr(s)

and then view it:

sage: L = [MatrixSpace(ZZ,3).random_element() for i in [0..8]]
sage: view(matrix_array(L,ncols=3))