5
$\begingroup$

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:

enter image description here

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"?

$\endgroup$
1
  • $\begingroup$ Thank you for adding the corresponding method for a pre-formed box, and for the accept! $\endgroup$
    – MarcoB
    Commented Sep 13, 2015 at 19:55

1 Answer 1

6
$\begingroup$

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],
      Row[PadLeft[Table[1, {n}], P]]
    ][x], "pvB"
  ]

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

enter image description here


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"]
$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Commented May 15, 2018 at 18:36
  • $\begingroup$ @IstvánZachar Very good points. Thank you for the edits as well. $\endgroup$
    – MarcoB
    Commented May 15, 2018 at 20:27

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.