I would like to define a version of MatrixForm that prints entries equal to zero in gray. The definition
matrixform[X_] := MatrixForm[X /. entry_ /; entry == 0 -> Style[0, LightGray]]
produces an output that looks how I'd want, but it actually changes the entries, rather than just the way they are displayed, so one cannot just use the output of my matrixform via % in algebraic manipulations.
Ideally I'm looking for an answer that works for sparse arrays too, without the conversion to a normal array: at least, I'd like to be able to work with the output without having to convert it back to a sparse array.
Note that I don't want just all zeroes in my notebook to be formatted in gray (so I don't think I can use Format), and I don't want matrices to be formatted as above automatically either.
Edit. Here is an example of what I'm hoping to achieve:
A = SparseArray[{1,1}->x,{2,2}]
(* Out: SparseArray[..., Specified elements: 1, Dimensions: {2,2}] as usual *)
% // matrixform
(* Out: MatrixForm of A with 0s shown in gray *)
2 %
(* Out: SparseArray[..., Specified elements: 1, Dimensions: {2,2}] as usual *)
% // matrixform
(* Out: MatrixForm of 2*A with 0s shown in gray *)





output-formattingandformatting, so I've used both; feel free to edit them. – Jules Lamers Feb 05 '18 at 13:57