How to make Mathematica show matrices and vectors nicely

It shows me like {{0}, {1}, {0}, {-1}} . Is it possible to make it look like a vector, always?

• MatrixForm is what you are looking for. Commented May 18, 2015 at 2:36
• I know about matrixform, but I dont want to type it everytime. Commented May 18, 2015 at 2:52
• Two different users provided a $PrePrint solution in this Q&A: (3098). Perhaps this question should be close as a duplicate of that more elaborate one? Commented May 18, 2015 at 6:07 • @Mr.Wizard I also thought to flag it for this, but this one actually is a really different question. Commented May 18, 2015 at 12:45 2 Answers Add this to your notebook or init file $PrePrint = If[MatrixQ[#], MatrixForm[#], #] &;


Then all matrices will automatically display as MatrixForm

and

If you want to format lists as column vectors also, try

\$PrePrint =
Which[MatrixQ[#], MatrixForm[#], VectorQ[#], ColumnForm[#],
True, #] &;


Now also

As @kattern pointed out, MatrixForm will pretty print your lists to look like matrices.

{{0}, {1}, {0}, {-1}} // MatrixForm


A word of caution, however: MatrixForm can get in the way of your calculations if you are not careful. See this question and the related answers: Why does MatrixForm affect calculations?.

For instance, you could get bitten by something like this:

matWRONG = {{0}, {1}, {0}, {-1}} // MatrixForm
(matCORRECT = {{0}, {1}, {0}, {-1}}) // MatrixForm


Both expressions print out a nice formatted version of your vector, but there is a subtle difference.

• In the first case, you assigned the graphical output of MatrixForm, i.e. the pretty-printed form, to the variable matWRONG. That's probably not what you meant to do.
• The second version assigns the vector to the matCORRECT variable, then pretty-prints the value of that variable. The variable itself contains the vector, and can be further operated upon.

For instance, you can transpose the matCORRECT vector, but if you try to do the same on the matWRONG one, Transpose will not recognize its input as a vector and return unevaluated, and you will probably be confused.

Transpose[matCORRECT]
Transpose[matWRONG]


• would the macro he wrote cause any problems like this? Commented May 18, 2015 at 3:10
• @grdgfgr As far as I know, it won't. In my understanding, in that case the pretty-printing will happen "last", i.e. after the assignments etc have already been taken care of. Commented May 18, 2015 at 3:28