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.

I know that if I use

CenterDot @@ (Superscript @@@ FactorInteger[x])

Mathematica will pretty print the output. However, is it possible to tell Mathematica to automatically format the output of FactorInteger with CenterDot and Superscript?

share|improve this question
you can just define your own function: e.g.fi[x_]:=CenterDot @@ (Superscript @@@ FactorInteger[x]) –  ubpdqn Apr 5 at 3:59
I know, but I want to see if it is possible to somehow add onto the built in function using some sort of preprinting directive like "$PrePrint = If[MatrixQ[#],MatrixForm[#],#]&;" –  user2612743 Apr 5 at 4:01
sorry cannot help in this regard –  ubpdqn Apr 5 at 5:05
I think it's not a good idea to try to do this. Modifying the builtin is definitely a bad idea. It's probably being used by other functions. There are some horror stories on this site about what happens when you modify builtins. About an analogue of the MatrixForm thing, the output is so generic that it's not really possible to detect that it came from FactorInteger. Just define your own function as ubpdqn said! –  Szabolcs Apr 5 at 5:06

1 Answer 1

up vote 3 down vote accepted

This is the best I can come up quickly. It can be used much in the same way that MatrixForm is.

SetAttributes[factorizationForm, HoldFirst];
factorizationForm[expr_] :=
  If[Head[Unevaluated[expr]] === FactorInteger,
    CenterDot @@ Superscript @@@ expr,


FactorInteger[5!] // factorizationForm



{{2, 3}, {3, 1}, {5, 1}} // factorizationForm

{{2, 3}, {3, 1}, {5, 1}}

I think it satisfies the spirit of your question even if it's not what you asked for to the letter.

share|improve this answer
I tried to combine this along with the matrix form to get: $PrePrint = If[MatrixQ[#], If[Head[Unevaluated[#]] === FactorInteger, CenterDot @@ Superscript @@@ #, MatrixForm[#]],#]&; –  user2612743 Apr 5 at 6:09
but it does not seem to give the desired result of printing the factorform if it is FactorInteger and otherwise printing it in matrix form. Any idea why? –  user2612743 Apr 5 at 6:09
Just a couple of ideas. The function you give to $PrePrint doesn't have the HoldFirst attribute and it doesn't return one of the formatted forms, but the evaluated, but unformatted, form of its argument. –  m_goldberg Apr 5 at 13:19
How would you fix it? Do you just do $Preprint = HoldFirst[...]? –  user2612743 Apr 5 at 16:52
@user2612743. I'm sorry, but my best advice is not to fix it, but to forget about monkeying with $Preprint (which can have strange side-effects unless you know exactly what you are doing) until you have a much better understanding of how Mathematica works. If you don't understand that HoldFirst is an attribute and not a function and what difference that makes, you are not ready to mess with $Preprint. I do recommend this download if you want to learn more. –  m_goldberg Apr 5 at 23:41

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.