MakeBoxes
MakeBoxes[expr_, form_]
an output handler expression acting as UpValues
for other expression converts it to a decorated form, which is then rendered by an editor.
MakeBoxes
is applied only to the output expressions in a normal Wolfram cells, Slides and WLX. It will not affect any intermediate operations.
MakeBoxes[..., StandardForm]
is applied to any visible output from the cell. It is also a part of a pipeline for ToString[..., StandardForm]
used in CellPrint, and EditorView for various applications.
Supported forms
Used together with
Applications
It is a core concept of the Notebook interface
Creating interactive objects
Used by
- Graphics
- Graphics3D
- ListLinePlotly
- Plotly
- EventObject
- many more
All graphics and interactive objects are running on WLJS interpreter, which is browser'a minimal Wolfram Language interpreter running on Javascript. It draws graphics, handles users interaction via JS. To explicitly run an expression on browser's side you need to apply CreateFrontEndObject or use ViewBox. This can be done automatically using MakeBoxes
for example
...
ListLinePlotly /: MakeBoxes[ListLinePlotly[args__], StandardForm] := With[{o = CreateFrontEndObject[ListLinePlotly[args]]},
MakeBoxes[o, StandardForm]
]
ListPlotly /: MakeBoxes[ListPlotly[args__], StandardForm] := With[{o = CreateFrontEndObject[ListPlotly[args]]},
MakeBoxes[o, StandardForm]
]
...
Styling symbols
Please consider to use StandardForm
for form
argument to achieve those effects.
Data preview
One can make a preview of the data for example
dataHolder /: MakeBoxes[dataHolder[data_], StandardForm] := With[{
display = ListPlot[data, ImageSize->200, Axes->False, ImagePadding->None] // CreateFrontEndObject
},
InterpretationBox[MakeBoxes[display, StandardForm], data]
]
dataHolder /: ListLinePlot[d_dataHolder, opts___] := ListLinePlot[d//First, opts]
dataHolder[RandomReal[{-1,1}, 100]]
dataHolder[RandomReal[{-1,1}, 100]] // ListLinePLot
ViewBox creates less overhead compared to InterpretationBox, when it comes to replacing symbols with Graphics or other interactive objects.
For just a one-time decoration - use Interpretation