Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  Mike Honeychurch Jul 9 at 22:49
    
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. –  bobthechemist Jul 10 at 1:13

2 Answers 2

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[
   Interpretation[
    Row[{
      HoldForm[myFN][
       DynamicModule[{open = False},
        Panel[Grid[{{
            Opener[Dynamic[open]],
            Graphics[{Green, Rectangle[]}, 
             ImageSize -> {Automatic, 
               Dynamic[
                3.5*(CurrentValue["FontCapHeight"]/
                   AbsoluteCurrentValue[Magnification])]}],
            PaneSelector[{
              False -> Row[{"Domain: ", Reals}],
              True -> Column[{Row[{"Domain: ", Reals}], 
                              Row[{"Formula: ", myFN[n][\[FormalX]]}]
                       }]},
             Dynamic[open],
             ImageSize -> Automatic (* pane resizes to current expression *)
             ]
            }}, Alignment -> {Left, Top}]] (* grid alignment *)
        ]]}],
    myFN[n]],  (* interpretation *)
   fmt];

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

Usage:

f = makeFN[3]

Mathematica graphics

f[4]
(* 64 *)

With the Opener open:

makeFN[5]

Mathematica graphics

Copying the output from above and evaluating it at 2:

Mathematica graphics

(* 32 *)
share|improve this answer
    
related use of Interpretation mathematica.stackexchange.com/questions/29854/… –  Mike Honeychurch Jul 10 at 3:41

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]

to

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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