def textmatrix(varname, a, fmt='4.3g'):
    """Convert matrix to multiline text representation, like

    varname = [ 1  2 ]
              [ 3  4 ]
    """
    prefix = f'{varname} = '
    prespc = ' '*len(prefix)
    lines = []
    fmt = f'{{:{fmt}}}'
    for i, row in enumerate(a):
        xs = [fmt.format(x) for x in row]
        line = '  '.join(xs)
        line = (prespc if i else prefix) + f'[ {line} ]'
        lines.append(line)
    return '\n'.join(lines)