In the version 10, a lot of functions returned a box with brief information which is very useful.

For example:

Interpolation[{1, 2, 3, 5, 8, 5}]

enter image description here

So what's that little box, and how can I make a function that return a similar box which contains some of the information?

| improve this question | | | | |
  • $\begingroup$ the little box is just a Panel with some info. I'll see if i can find a link to how to make them in your own functions. darren glosemeyer (formerly) at WRI wrote this up a few years ago. $\endgroup$ – Mike Honeychurch Jul 9 '14 at 22:49
  • $\begingroup$ and FWIW they are terribly annoying on the RPi, as it oftentimes takes longer to render the box than it does to run the underlying function. $\endgroup$ – bobthechemist Jul 10 '14 at 1:13

You can use MakeBoxes to format output pretty much however you like. This is what Mathematica does for InterpolatingFunction. You may be able to glean something by inspecting the output cell or from FormatValues[InterpolatingFunction]. Unlike InterpolatingFunction, I included an Interpretation, which means that the output in the notebook may be copied and used. The InterpolatingFunction has a little + button that toggles between information panes. I've included a PaneSelector and an Opener for that feature, in case you wanted that. Just like InterpolatingFunction, this leaves little Dynamic bits littering your notebook.

Toy example:

MakeBoxes[myFN[n_], fmt_] := ToBoxes[
       DynamicModule[{open = False},
            Graphics[{Green, Rectangle[]}, 
             ImageSize -> {Automatic, 
              False -> Row[{"Domain: ", Reals}],
              True -> Column[{Row[{"Domain: ", Reals}], 
                              Row[{"Formula: ", myFN[n][\[FormalX]]}]
             ImageSize -> Automatic (* pane resizes to current expression *)
            }}, Alignment -> {Left, Top}]] (* grid alignment *)
    myFN[n]],  (* interpretation *)

makeFN[n_?NumericQ] := myFN[n];
myFN[n_?NumericQ][x_] := x^n


f = makeFN[3]

Mathematica graphics

(* 64 *)

With the Opener open:


Mathematica graphics

Copying the output from above and evaluating it at 2:

Mathematica graphics

(* 32 *)
| improve this answer | | | | |

The info on Mathgroup by Darren Glosemeyer here wasn't exactly what I remembered but if you change this line:

makeWrapper[data_List, var_Symbol, opts___] := myWrapper[data, var]


makeWrapper[data_List, var_Symbol, opts___] := myWrapper[Panel[data], var]

you can see how to include panels in your own functions:

enter image description here

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.