5
$\begingroup$

Is there a way to ensure that every time I perform an operation such as RowReduce, Linear Solve, Null Space, Inverse, Eigenvectors, etc. that the matrix is displaying in MatrixForm instead of applying the postfix form of MatrixForm every time (//MatrixForm)? For example, is there a variable in the Option Inspector to set the default form of an array? I checked but couldn't find anything of the sort. If not, I am going to make a feature request for a future release of Mathematica.

$\endgroup$
10
$\begingroup$

You can use $PrePrint:

enter image description here

$PrePrint = If[MatrixQ @ #, MatrixForm @ #, #] &;

Array[x, {4, 5}]

enter image description here

{{a, b}, {x, y}}

enter image description here

SeedRandom[1];
rm = RandomInteger[10, {5, 5}]

enter image description here

N @ Eigenvectors[rm]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ How do create a global matrix preprint setting? It reverts back after I close the kernel. $\endgroup$ Dec 1 '21 at 1:20
3
$\begingroup$

An alternative is to teach StandardForm about your desired formatting:

Unprotect[StandardForm];
StandardForm /: MakeBoxes[l_List, StandardForm] /; MatrixQ @ Unevaluated @ l := MakeBoxes[MatrixForm[l]]
Protected[StandardForm];
$\endgroup$
3
  • $\begingroup$ Is this to be applied in a notebook or init.m? $\endgroup$ Dec 6 '21 at 20:14
  • $\begingroup$ That is up to you. $\endgroup$
    – Carl Woll
    Dec 6 '21 at 20:14
  • $\begingroup$ My init.m changes are undone after I restart. How do I make permanent modifications? $\endgroup$ Dec 6 '21 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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