# Representing Textual Forms by Boxes

All textual and graphical forms in *Mathematica* are ultimately represented in terms of nested collections of *boxes*. Typically the elements of these boxes correspond to objects that are to be placed at definite relative positions in two dimensions.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]//DisplayForm= | |

DisplayForm[boxes] | show boxes as they would be displayed |

Showing the displayed form of boxes.

In[3]:= |

Out[3]//DisplayForm= | |

In[4]:= |

Out[4]//DisplayForm= | |

In[5]:= |

Out[5]//DisplayForm= | |

"text" | literal text |

RowBox[{a,b,...}] | a row of boxes or strings |

GridBox[{{a_{1},b_{1},...},{a_{2},b_{2},...},...}] | |

a grid of boxes | |

SubscriptBox[a,b] | subscript |

SuperscriptBox[a,b] | superscript |

SubsuperscriptBox[a,b,c] | subscript and superscript |

UnderscriptBox[a,b] | underscript |

OverscriptBox[a,b] | overscript |

UnderoverscriptBox[a,b,c] | underscript and overscript |

FractionBox[a,b] | fraction |

SqrtBox[a] | square root |

RadicalBox[a,b] | b root |

In[6]:= |

Out[6]//DisplayForm= | |

In[7]:= |

Out[7]//DisplayForm= | |

In[8]:= |

Out[8]//DisplayForm= | |

FrameBox[box] | render box with a frame drawn around it |

GridBox[list,RowLines->True] | put lines between rows in a GridBox |

GridBox[list,ColumnLines->True] | put lines between columns |

GridBox[list,RowLines->{True,False}] | |

put a line below the first row, but not subsequent ones |

Inserting frames and grid lines.

In[9]:= |

Out[9]//DisplayForm= | |

In[10]:= |

Out[10]//DisplayForm= | |

In[11]:= |

Out[11]//DisplayForm= | |

StyleBox[boxes,options] | render boxes with the specified option settings |

StyleBox[boxes,"style"] | render boxes in the specified style |

Modifying the appearance of boxes.

StyleBox takes the same options as Style. The difference is that Style is a high-level function that applies to an expression to determine how it will be displayed, while StyleBox is the corresponding low-level function in the underlying box structure.

In[12]:= |

Out[12]//DisplayForm= | |

In[13]:= |

Out[13]//DisplayForm= | |

In[14]:= |

Out[14]//DisplayForm= | |

If you use a notebook front end for *Mathematica*, then you will be able to change the style and appearance of what you see on the screen directly by using menu items. Internally, however, these changes will still be recorded by the insertion of appropriate StyleBox objects.

FormBox[boxes,form] | interpret boxes using rules associated with the specified form |

InterpretationBox[boxes,expr] | interpret boxes as representing the expression expr |

TagBox[boxes,tag] | use tag to guide the interpretation of boxes |

ErrorBox[boxes] | indicate an error and do not attempt further interpretation of boxes |

Controlling the interpretation of boxes.

In[15]:= |

Out[15]//DisplayForm= | |

In[16]:= |

Out[16]//InputForm= | |

In[17]:= |

Out[17]//DisplayForm= | |

In[18]:= |

Out[18]//InputForm= | |

If you edit the boxes given in an InterpretationBox, then there is no guarantee that the interpretation specified by the interpretation box will still be correct. As a result, *Mathematica* provides various options that allow you to control the selection and editing of InterpretationBox objects.

option | default value | |

Editable | Automatic | whether to allow the contents to be edited |

Selectable | True | whether to allow the contents to be selected |

Deletable | True | whether to allow the box to be deleted |

DeletionWarning | False | whether to issue a warning if the box is deleted |

BoxAutoDelete | False | whether to strip the box if its contents are modified |

StripWrapperBoxes | False | whether to remove StyleBox etc. from within boxes in TagBox[boxes, ...] |

Options for InterpretationBox and related boxes.

TagBox objects are used to store information that will not be displayed but which can nevertheless be used by the rules that interpret boxes. Typically the tag in TagBox[boxes, tag] is a symbol which gives the head of the expression corresponding to boxes. If you edit only the arguments of this expression then there is a good chance that the interpretation specified by the TagBox will still be appropriate. As a result, Editable->True is effectively the default setting for a TagBox.

The rules that *Mathematica* uses for interpreting boxes are in general set up to ignore details of formatting, such as those defined by StyleBox objects. Thus, unless StripWrapperBoxes->False, a red , for example, will normally not be distinguished from an ordinary black .

In[19]:= |

Out[19]= |