MatrixForm uses "round brackets" as delimiter. These are like parentheses, but contrary to "regular" parentheses, they stretch vertically to accommodate the height of their contents. For example:

MatrixForm[{{1, 2}, {3, 4}, {5, 6}}]

...is displayed like this

Mathematica graphics

I want to design an output format similar to MatrixForm, but using (vertically-expanding) square brackets instead.

How can I do this?


Bizarrely/perversely enough, Mathematica provides a way to produce the 90-degree-rotated version of what I want to do1:

Overscript[Underscript[
  Grid[{{1, 2, 3}, {4, 5, 6}}], \[UnderBracket]],
  \[OverBracket]
]

Mathematica graphics


1 Even more bizarre (to me at least) is the fact that, in the code shown above, the second arguments to Overscript and Underscript are unquoted strings. Somehow, the Mathematica parser recognizes these special characters as valid Mathematica expressions all by themselves. What's up with that??? But that's really a topic for another post.

  • @FredSimons: My apologies! I managed to drop that crucial detail in the translation. I will delete the misleading EDIT and comment shortly. – kjo Jun 12 '15 at 14:11
  • 1
    There are no unquoted strings here: \[UnderBracket] is a Symbol, just like, say, x. Try Head[\[UnderBracket]] to see what I mean. – 2012rcampion Jun 12 '15 at 17:29
up vote 16 down vote accepted

From very old documentation (link to Wolfram website): "Parentheses within a single RowBox by default grow to span whatever other objects appear in the RowBox. Some expandable characters, however, grow by default only to a limited extent."

The latter seems to apply to square brackets. But we can overcome that by using a StyleBox:

StyleBox [RowBox[{"[",  GridBox[{ {"1", "2"},{"3", "4"},{"5", "6"}}],  "]"}], 
  SpanMaxSize->Infinity] // DisplayForm

This produces MatrixForm with square brackets.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.