'This method factors out what is essentially grid printing.'

def _print_matrix_contents(self, e):

    M = e
    Ms = {}
    for i in range(M.rows):
        for j in range(M.cols):
            Ms[(i, j)] = self._print(M[(i, j)])
    hsep = 2
    vsep = 1
    maxw = ([(-1)] * M.cols)
    for j in range(M.cols):
        maxw[j] = max(([Ms[(i, j)].width() for i in range(M.rows)] or [0]))
    D = None
    for i in range(M.rows):
        D_row = None
        for j in range(M.cols):
            s = Ms[(i, j)]
            assert (s.width() <= maxw[j])
            wdelta = (maxw[j] - s.width())
            wleft = (wdelta // 2)
            wright = (wdelta - wleft)
            s = prettyForm(*s.right(('    ' * wright)))
            s = prettyForm(*s.left(('    ' * wleft)))
            if (D_row is None):
                D_row = s
                continue
            D_row = prettyForm(*D_row.right(('    ' * hsep)))
            D_row = prettyForm(*D_row.right(s))
        if (D is None):
            D = D_row
            continue
        for _ in range(vsep):
            D = prettyForm(*D.below('    '))
        D = prettyForm(*D.below(D_row))
    if (D is None):
        D = prettyForm('')
    return D
