3

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}], PointSize@0.08, PointBox[{p1, p2}]}, 
  ImageSize -> 70]

which produces the desired result:

enter image description here

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

enter image description here

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.

glS
  • 7,623
  • 1
  • 21
  • 61

1 Answers1

2

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]

test1

Testing with points lying on the circle.

foo @@@ N[CirclePoints[5]]

test2

??foo

info

m_goldberg
  • 107,779
  • 16
  • 103
  • 257