# Strange behavior of UpSetDelayed together with MakeBoxes

In order to answer this question, I just stumbled into the world of UpValues. Though I managed to find a solution for the problem, I'm confused by my own code now 囧, consider the following line of code:

baseForm /: MakeBoxes[baseForm[a_, b_], fmt_] := ToBoxes@BaseForm[a, b]


It makes baseForm display like BaseForm, by setting upvalue to… where?

"That goes without saying, it's in baseForm!" Huh?:

UpValues /@ {baseForm, TagSetDelayed, MakeBoxes, a, b,
Pattern, fmt, SetDelayed, ToBoxes, BaseForm}
(* {{}, {}, {}, {}, {}, {}, {}, {}, {}, {}} *)


The upvalue(?) can be found in the Information of baseForm, indeed:

??baseForm


But where is it stored in?

Assignments to MakeBoxes and Format get special treatment. The definitions are stored as (under-documented) FormatValues:

FormatValues[baseForm] // InputForm

(*
{HoldPattern[MakeBoxes[baseForm[a_, b_], fmt_]] :> ToBoxes[BaseForm[a, b]]}
*)


Note that if we omit InputForm from the expression above, then the system will attempt to apply the formatting to baseForm within the definition itself and give a misleading result:

FormatValues[baseForm]

(*
BaseForm::intpm: Positive machine-sized integer expected at position 2 in BaseForm[a_,b_]. >>

BaseForm::intpm: Positive machine-sized integer expected at position 2 in BaseForm[a,b]. >>

{HoldPattern[MakeBoxes[BaseForm[a_,b_],fmt_]]:>ToBoxes[BaseForm[a,b]]}
*)

• Wow, I didn't even know that FormatValues existed! "Under-documented" even feels a bit euphemistic though... – sebhofer Nov 26 '15 at 15:51
• Gee, I stumbled over this problem now for the second time. Good to have StackExchange. I wish I could upvote for a second time. Many thanks to WReach! – Henrik Schumacher Dec 6 '17 at 9:30