I have never used low-level formating functions, so this problem might have a simple solution. I'm currently pulling my hair out trying to solve it, however. Consider the following example:
foo = DiagonalMatrix[{1, 1}]
(*{{1, 0}, {0, 1}}*)
bar = {{1, 0}, {0, 1}}
(*{{1, 0}, {0, 1}}*)
GridBox[foo] // DisplayForm
(*GridBox[{{1, 0}, {0, 1}}]*)
GridBox[bar] // DisplayForm
(*gives correctly formated output*)
Why does the DisplayForm depend on the way the list was created?
Edit: I contacted WRI Technical support and got the following answer:
GridBox is doing what it should do. Box forms interpret strings and boxes and not Mathematica expressions. Thus there is no reason to expect GridBox to interpret a packed array which is a compiled expression. Grid uses GridBox for the formatting but unpacks first.
I guess the bottomline is, use Grid instead of GridBox if possible (just as I should have done), or unpack arrays in advance.
foo1=foo
the weirdness happens withfoo1
as well. $\endgroup$foo===bar
yieldsTrue
... $\endgroup$