# Custom MakeBoxes are issued also for different pattern expressions

Suppose I want to display some expression, say foo[p1_,p2_], as a point in a circle.

I can achieve this using MakeBoxes, like in the following:

ClearAll[foo];
foo /: MakeBoxes[foo[p1_, p2_], fmt_] :=
GraphicsBox[{CircleBox[{0, 0}], [email protected], PointBox[{p1, p2}]},
ImageSize -> 70]


which produces the desired result:

However, a problem arises when I use ??foo:

As you can see, Mathematica is also issuing MakeBoxes on the foo[p1_,p2_] that should appear in the informations. Infact, the problem can be traced back to the fact that also the expression

foo[a_,b_]


triggers the MakeBoxes evaluation.

How can this problem be avoided?

PS: apologies for the not-much-informative title, please change it if you find a better way to describe the question.

• Why not restrict the argument, since the display will only make sense for those arguments: MakeBoxes[foo[p1_?NumberQ, p2_?NumberQ], fmt_]? Commented Feb 27, 2016 at 1:35

I concur with the answer J.M. gave in a comment to the question, but would limit evaluation by a condition that constrain the coordinates given to lie on or within the unit circle.

ClearAll[foo];
foo /: MakeBoxes[foo[p1_, p2_] /; Norm[{p1, p2}] <= 1, form_] :=
GraphicsBox[{CircleBox[{0, 0}], PointSize @ .08, PointBox[{p1, p2}]},
ImageSize -> 70]


Testing with points along the ray through {1, 1}

foo[#, #] & /@ Range[0, 1, .5]


Testing with points lying on the circle.

foo @@@ N[CirclePoints[5]]


??foo