Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.