BUILT-IN MATHEMATICA SYMBOL

TemplateBox

TemplateBox[{box1, box2, ...}, tag]
is a low-level box structure that parameterizes the display and evaluation of the boxes .

Details and OptionsDetails and Options

  • The parameters of TemplateBox are plugged into functions that create new box expressions to be used for display or evaluation. The option DisplayFunction specifies the function used to construct boxes for display, while InterpretationFunction specifies the function used for evaluation.
  • If the tag of the TemplateBox is a string, then that style will be used for the TemplateBox.
  • The following options can be given:
  • DisplayFunctionNonepure function that assembles into a box structure for display
    EditableAutomaticwhether to allow to be edited
    InterpretationFunctionAutomaticpure function that assembles into a box structure for evaluation
    SelectableAutomaticwhether to allow to be individually selected
    TooltipNonetooltip to display when the mouse cursor is over the box
    TooltipStyle{}style specifications for the tooltip
    TooltipDelay0.how long to delay before displaying the tooltip
  • DisplayFunction and InterpretationFunction only accept pure functions that allow for simple rearrangement and substitution into a box structure. The functions do not evaluate in the Mathematica kernel and do not support standard kernel functionality.
  • If the DisplayFunction is specified on the stylesheet, all displayed instances of the TemplateBox change uniformly when the stylesheet changes.
  • One important aspect of a TemplateBox is that it will only allow you to edit and interact with the box arguments to the TemplateBox, and not the boxes that are part of the DisplayFunction.
  • For default input and output cells, if you copy an expression containing a TemplateBox, Mathematica places the the fully resolved InterpretationFunction on the clipboard so that evaluation semantics are preserved in copy/paste. Copy As ► Plain Text will copy the DisplayFunction boxes.
  • You can write MakeBoxes and MakeExpression rules that use TemplateBox in order to define new notations.
  • If a TemplateBox cannot support arbitrary box expressions as parameters, it is generally advisable to use the option Editable->False to prevent users from editing the parameters.

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

The binomial style is present in the core stylesheet so its DisplayFunction is used when assembling the box to display:

In[1]:=
Click for copyable input
Out[1]=

The actual DisplayFunction of the binomial style specified in the core stylesheet is .

Many special functions are represented using template boxes. For example, the function LegendreP is typeset in TraditionalForm using a TemplateBox:

In[2]:=
Click for copyable input
Out[2]=

We can specify the display function of the TemplateBox explicitly, but it is usually specified on the stylesheet:

In[3]:=
Click for copyable input
Out[3]=

TemplateBox can be nested to any level:

In[4]:=
Click for copyable input
Out[4]=
New in 7.0
New to Mathematica? Find your learning path »
Have a question? Ask support »