6
$\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$

3 Answers 3

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$ Commented Dec 1, 2021 at 1:20
4
$\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$ Commented Dec 6, 2021 at 20:14
  • $\begingroup$ That is up to you. $\endgroup$
    – Carl Woll
    Commented Dec 6, 2021 at 20:14
  • $\begingroup$ My init.m changes are undone after I restart. How do I make permanent modifications? $\endgroup$ Commented Dec 6, 2021 at 20:27
2
$\begingroup$

Here's how to automatically view two-dimensional arrays in matrix form using the Option Inspector to change from StandardForm to TraditionalForm.

  1. Launch Mathematica.
  2. On the Mathematica main menu, select Mathematica > Settings...
  3. Click on the Advanced tab.
  4. Click on the Open Option Inspector button.
  5. In the Options column, open Cell Options > New Cell Defaults > CommonDefaultFormatTypes.
  6. Within the CommonDefaultFormatTypes folder, find the word "Output." Click to the far left of the word "Output" (near the left edge of the dialog box in the Set column).
  7. To the right of the word "Output", double-click on the words StandardForm and replace them with the words TraditionalForm
  8. Press the enter key.
  9. Close all open dialog boxes. This change should now be permanent in future sessions for the current user.

This procedure worked for me with Mathematica 13.1 and is a very slightly updated version of the following link.

https://support.ti.davidson.edu/hc/en-us/articles/115011833707-Display-Mathematica-Matrices-in-2D-Format

$\endgroup$
2
  • $\begingroup$ Please include the detailed procedure in your answer rather than relying on the link, which eventually will break. $\endgroup$
    – MarcoB
    Commented Mar 17 at 11:23
  • $\begingroup$ Thanks. Made the change you requested. $\endgroup$ Commented Mar 18 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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