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?

  • 2
    $\begingroup$ you can just define your own function: e.g.fi[x_]:=CenterDot @@ (Superscript @@@ FactorInteger[x]) $\endgroup$
    – ubpdqn
    Commented Apr 5, 2014 at 3:59
  • $\begingroup$ 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[#],#]&;" $\endgroup$
    – 1110101001
    Commented Apr 5, 2014 at 4:01
  • $\begingroup$ sorry cannot help in this regard $\endgroup$
    – ubpdqn
    Commented Apr 5, 2014 at 5:05
  • 3
    $\begingroup$ 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! $\endgroup$
    – Szabolcs
    Commented Apr 5, 2014 at 5:06

1 Answer 1


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.

  • $\begingroup$ I tried to combine this along with the matrix form to get: $PrePrint = If[MatrixQ[#], If[Head[Unevaluated[#]] === FactorInteger, CenterDot @@ Superscript @@@ #, MatrixForm[#]],#]&; $\endgroup$
    – 1110101001
    Commented Apr 5, 2014 at 6:09
  • $\begingroup$ 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? $\endgroup$
    – 1110101001
    Commented Apr 5, 2014 at 6:09
  • $\begingroup$ 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. $\endgroup$
    – m_goldberg
    Commented Apr 5, 2014 at 13:19
  • $\begingroup$ How would you fix it? Do you just do $Preprint = HoldFirst[...]? $\endgroup$
    – 1110101001
    Commented Apr 5, 2014 at 16:52
  • $\begingroup$ @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. $\endgroup$
    – m_goldberg
    Commented Apr 5, 2014 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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