This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / Demos / Notations / ...Advanced Features /

Note: This section is intended for advanced users.

Tag boxes

A TagBox is a box structure just like, SubscriptBox, GridBox. It is used to change the structure of an expression or indicate a grouping or interpretation of a subexpression at an underlying level. To illustrate tag boxes consider the following input which contains an embedded TagBox.

All Mathematica input and output is made up of box structures at a low level. When Mathematica receives input, these box structures are parsed into internal expressions, which can be thought of as full form expressions. Internal evaluation then takes place, and finally the internal structures are transformed back into box structures for displaying in the Mathematica front end.We can reveal how Mathematica sees this input at a low level by using the Show Expression command under the Format menu.

Here is the underlying representation of the expression above in terms of boxes, displayed using the Show Expression menu item located under the Format menu.

The above expression contains a subexpression TagBox[SuperscriptBox["x", "2"],foo]]. It is important to note that this box expression as normally viewed in Mathematica looks visually like even though it has an embedded TagBox. Information contained in the tag is visually hidden from the user. When an expression containing a TagBox is input into Mathematica the default interpretation of the subexpression surrounded by the TagBox is to wrap the TagBox name around the parsed subexpression, in this case to wrap foo around x^2.

The embedded TagBox tag foo has no special parsing behavior associated with it.

However you can define your own rules for the way specific tag boxes are parsed. For instance by using the low level function MakeExpression we can change how Mathematica will parse expressions containing TagBoxes.

By defining a new rule for MakeExpression we can change how Mathematica will parse expressions containing a TagBox with the tag literalBoxes.

The embedded TagBox tag literalBoxes now has the special parsing behavior associated with it to just return the boxes.

Knowing that special behaviors can be set up for specific tags we can now examine the tags defined by the Notation package. The Notation package defines three tags that have special behaviors: NotationBoxTag, NotationPatternTag, and NotationMadeBoxesTag.