# How to format symbols with tooltip in TraditionalForm?

This is a follow up to this previous question, where a TraditionalForm formatting was defined for the symbol pvB, so that TraditionalForm[pvB[2,4,x,s,m0,m1]] would give $B_{0011}(s,m0,m1)$.

I now want to mimic the behavior of TraditionalForm formatting of built-in special functions, where hovering the cursor over it would display a tooltip with the name of the built-in symbol.

Below is such an example. Hovering the mouse over the TraditionalForm version of the BesselJ function displays the tooltip:

How do I modify the code of the answers given to this previous question so that hovering over $B_{0011}(s,m0,m1)$ would give a tooltip message "PVB"?

• Thank you for adding the corresponding method for a pre-formed box, and for the accept! Sep 13, 2015 at 19:55

This should be as simple as wrapping any one of the answers to your previous question within Tooltip. In this case, I prefer to start from Mr. Wizard's answer, because it allows me to stay away from explicitly building up the necessary Box expression.

MakeBoxes[pvB[n_Integer, P_Integer, _, x__], fmt : TraditionalForm] :=
MakeBoxes[#, fmt] &@
Tooltip[
Subscript[
Defer[B],
][x], "pvB"
]

pvB[3, 5, x, s, m0, m1] // TraditionalForm


edit by QuantumDot

And if you already have a Box expression, then wrap with TooltipBox. For example, using Jens' answer,

pvB /: MakeBoxes[pvB[n1_Integer, n2_Integer, x_, s_, m0_, m1_], TraditionalForm] :=
TooltipBox[
RowBox[{SubscriptBox["B",
RowBox[{Sequence @@ Riffle[Table["0", {n1}], "\[ThinSpace]"],
"\[ThinSpace]",
Sequence @@ Riffle[Table["1", {n2 - n1}], "\[ThinSpace]"]}]],
"(", Sequence @@ Riffle[Map[ToBoxes, {x, s, m0, m1}], ","], ")"}],
"pvB"]

• Just a caveat for the second approach: anything more complex than a String or List within the second argument of TooltipBox (e.g. TooltipBox[..., <||>]) needs to be wrapped into ToBoxes otherwise the tooltip won't format correctly. Moreover, the formatter should pre-check argument types, as in symbolic cases no formatting can be done (i.e. n1 and n2 must be integers). I have edited this into your answer. May 15, 2018 at 18:36
• @IstvánZachar Very good points. Thank you for the edits as well. May 15, 2018 at 20:27