# How to change the output format of a built-in function

Is it possible to change the output of build-in functions?

I would like to change the output for IdentityMatrix[n] to "I", so I tried

Format[IdentityMatrix[n]] := "I"


For comparison I also tried

Format[Sin[x_]] := "Sine(" <> ToString[x] <> ")"


Both result into an error: "Tag IdentityMatrix in IdentityMatrix[n] is Protected."

I guess these functions are protected because they are build-in functions. Is there a way to change the output format of a build-in function?

-

## 1 Answer

You can either Unprotect the symbol, or use MakeBoxes instead

MakeBoxes[IdentityMatrix[_], StandardForm] := "I"
MakeBoxes[Sin[x_], StandardForm] := "Sine(" <> ToString[x] <> ")"


Just know that this last option provides a default way of formatting, it doesn't override anything if there already is a rule

-
The matrix identity thing doesn't work for me in version 9. Do I need to do something else? I guess it evaluates to {{1,0},{0,1},...} before it gets to format it. –  masterxilo Dec 1 '14 at 13:02