This works for me in WW 2.14. But I had to use a Formula MathObject, not a Matrix. Depending on what else you are doing with $U, that may not be good.
EDIT: Now I see your more recent post. You are using things like the transpose method, which I will assume do not work on a Formula. But you could get around this by doing like:
$UforDisplay = Formula(...);
$U = Matrix("$UforDisplay");
and use them separately.
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
);
Context("Matrix")->flags->set(reduceConstants=>0,reduceConstantFunctions=>0);
$U = Formula("[
[sqrt(2),sqrt(2)],
[-sqrt(2),sqrt(2)]
]");
BEGIN_PGML
[`[$U]`]
END_PGML
ENDDOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
);
Context("Matrix")->flags->set(reduceConstants=>0,reduceConstantFunctions=>0);
$U = Formula("[
[sqrt(2),sqrt(2)],
[-sqrt(2),sqrt(2)]
]");
BEGIN_PGML
[`[$U]`]
END_PGML
ENDDOCUMENT();