RE: Re: Automatic Display in MatrixForm

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

Colin Rose commented on the MakeBoxes definition that would make StandardForm display matrices with the equivalent of MatrixForm. His comment included: ------------------ Two interesting cases are: (1) Output from Solve will now get displayed as a 'Matrix', which I think is highly undesirable. For instance, if Solve returns an answer such as {{x -> 3}} then it will now be presented as (x -> 3) which can cause a lot of confusion. I would suggest eliminating this possibility by adding the exclusion rule: FreeQ[t, Rule] === True to yield Function[t, MatrixQ[Unevaluated[t]] && (t =!= {{}} && FreeQ[t, Rule] === True), HoldAll] (2). Let: lis = { {}, {}, {}, {} ... } Some functions might generate output like this. This generates a BEEP when Mathematica tries to format it as a "Matrix". I can't think of a nice general way to exclude such cases. ------------------ REPLY: The version below takes care of both cases above. The exclusion used here is a little different from the one suggested above. Here 'MatrixForm' formatting isn't used on an empty matrix, or a matrix where *every* element has the head Rule or RuleDelayed. Other changes can be made as desired. MakeBoxes[m_?(Function[t,MatrixQ[Unevaluated[t]] && Flatten[t//.{_Rule->Sequence[],_RuleDelayed->Sequence[]}]=!={}, HoldAll ]), StandardForm] := RowBox[{"(", GridBox[Map[Function[t,MakeBoxes[t,StandardForm],HoldAll], Unevaluated[m],{2}]],")"}] -------------------- Regards, Ted Ersek For Mathematica tips, tricks see http://www.dot.net.au/~elisha/ersek/Tricks.html