TemplateBox

TemplateBox[{box1,box2,},tag]

is a low-level box structure that parameterizes the display and evaluation of the boxes boxi.

Details 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 boxi into a box structure for display
    EditableAutomaticwhether to allow boxi to be edited
    InterpretationFunctionAutomaticpure function that assembles boxi into a box structure for evaluation
    SelectableAutomaticwhether to allow boxi 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 Wolfram Language 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, not the boxes that are part of the DisplayFunction.
  • For default input and output cells, if you copy an expression containing a TemplateBox, the Wolfram System places 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.

Examples

open allclose all

Basic Examples  (3)

Display a template that is stored in the style "Binomial" in a stylesheet:

Display a template with an explicit DisplayFunction:

Use InterpretationFunction to control how a template evaluates:

Options  (6)

DisplayFunction  (2)

DisplayFunction overrides any DisplayFunction inherited from the stylesheet:

A DisplayFunction resulting in an invalid box structure can produce an error:

InterpretationFunction  (2)

The InterpretationFunction yields a box structure that will be used for evaluation:

This same structure used as input evaluates to LieBracket:

A value of Automatic causes tag to be used as the function head of the box structure:

SyntaxForm  (1)

SyntaxForm can be used to set the precedence of a TemplateBox used as an operator:

Tooltip  (1)

Specify the tooltip that will be displayed when the mouse hovers over a template box:

Tooltip->Automatic generates a tooltip from tag:

Introduced in 2008
 (7.0)
 |
Updated in 2010
 (8.0)