Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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