RE: making MatrixForm[] defaul
- To: mathgroup@smc.vnet.net
- Subject: [mg11443] RE: [mg11400] making MatrixForm[] defaul
- From: Ersek_Ted%PAX1A@mr.nawcad.navy.mil
- Date: Thu, 12 Mar 1998 01:33:38 -0500
Barry Wark wrote: ---------- |I am doing a lot of work in Mathematica for my linear algebra class. I |find that I'm doing a lot of MatrixForm[] around commands to generate |output that I am comfortable reading. Is there any way to make |MatrixForm the default method for displaying matricies (lists) so that |I don't have to keep typing it? | First I tried the code in the next line, and it works a lot of the time. ___________________ MakeBoxes[m_?MatrixQ, form_]:= RowBox[{"(",GridBox[Map[MakeBoxes[#, form]&, m, {2}]],")"}] But then if you evaluate: In[n]:= HoldForm[3*{{1,2},{3,4}}] you get the MatrixForm equivalent of {{3,6},{9,12}}. ____________________________________________________________________ Tech Support at Wolfram Research showed me how to fix this. Those guys are great. They said: Typesetting rules often require meticulous control of evaluation. Since the expression inside of Hold or HoldForm must be displayed, these rules are applied regardless of whether or not the enclosing expression would otherwise hold the expression unevaluated. The rule above was applied to HoldForm[3*{{1,2},{3,4}}] for the same reason that MatrixQ[3 * {{1, 2}, {3, 4}}] returns True. The original input isn't a matrix, but it evaluates to something that is a matrix, so the rule is applied. They suggested the following code which works much better. In[n]:= MakeBoxes[m_?(Function[t, MatrixQ[Unevaluated[t]]&&( t=!={{}} ), HoldAll]), form_]:= RowBox[{"(", GridBox[ Map[Function[t, MakeBoxes[t, form], HoldAll], Unevaluated[m],{2}]], ")"}] I put this in a package called matrix.m. Instead you could also put it in your init.m (this way it will always be used by default)! My matrix.m package also has code in it that makes it so you can use text book notation for Transpose[m] and Inverse[m]. Let me know if you want the details. Also: Make Boxes can be confusing. I could try to explain how it works if anyone is interested. Ted Ersek