RE: Automatic Display in MatrixForm

*To*: mathgroup at smc.vnet.net*Subject*: [mg19542] RE: Automatic Display in MatrixForm*From*: "Ersek, Ted R" <ErsekTR at navair.navy.mil>*Date*: Tue, 31 Aug 1999 00:52:28 -0400*Sender*: owner-wri-mathgroup at wolfram.com

Colin Rose wrote: ----------------------------- A few weeks ago, there was much excitement here when it was shown that one can get all the advantages of MatrixForm output, without the disadavantages ..... Now suppose: 1) We switch the above ON. 2) Then, how do we switch it off for a particular function's ouptut. That is, if MyFunc[x] returns a matrix, which we want formatted as a List (and not in "Fancy Matrix" form), how can we switch it off LOCALLY for this function's output only, and without converting back to InputForm ? ------------------------------ REPLY: The code below should do the trick. Notice I am using my latest version here which doesn't display the result from Solve or an empty matrix with 'MatrixForm'. For those who may be puzzled the (HiddenSymbols`) context is something I dreamed up. ------------------------------- In[1]:= $Pre:=(HiddenSymbols`UseMatrixForm=True;#&) In[2]:= MakeBoxes[m_?(Function[t,MatrixQ[Unevaluated[t]] && Flatten[t//.{_Rule->Sequence[],_RuleDelayed->Sequence[]}]=!={}, HoldAll ]), StandardForm]/;HiddenSymbols`UseMatrixForm := RowBox[{"(", GridBox[Map[Function[t,MakeBoxes[t,StandardForm],HoldAll], Unevaluated[m],{2}]],")"}] In[3]:= MyFunc[x_]:=(HiddenSymbols`UseMatrixForm=False;3 x) In[4]:= m={{1,2,1},{1,0,1},{0,0,1}} MyFunc[m] m.m Out[4]= 1 2 1 1 0 1 0 0 1 Out[5]= {{3,6,3},{3,0,3},{0,0,3}} Out[6]= 3 2 4 1 2 2 0 0 1 -------------------- Isn't that delicious. Ted Ersek For Mathematica tips, tricks see http://www.dot.net.au/~elisha/ersek/Tricks.html