# String Representation of Boxes

*Mathematica* provides a compact way of representing boxes in terms of strings. This is particularly convenient when you want to import or export specifications of boxes as ordinary text.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]//FullForm= | |

It is important to distinguish between forms that represent just raw boxes, and forms that represent the *meaning* of the boxes.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]//FullForm= | |

Distinguishing raw boxes from the expressions they represent.

If you copy the contents of a StandardForm cell into another program, such as a text editor, *Mathematica* will generate a form where necessary. This is done so that if you subsequently paste the form back into *Mathematica*, the original contents of the StandardForm cell will automatically be re-created. Without the , only the raw boxes corresponding to these contents would be obtained.

With default settings for options, forms pasted into *Mathematica* notebooks are automatically displayed in two-dimensional form.

Embedding two-dimensional box structures in strings.

*Mathematica* will usually treat a form that appears within a string just like any other sequence of characters. But by inserting a you can tell *Mathematica* instead to treat this form like the boxes it represents. In this way you can therefore embed box structures within ordinary character strings.

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

\(box_{1},box_{2},...\) | RowBox[box_{1},box_{2},...] |

box_{1}\^box_{2} | SuperscriptBox[box_{1},box_{2}] |

box_{1}\_box_{2} | SubscriptBox[box_{1},box_{2}] |

box_{1}\_box_{2}\%box_{3} | SubsuperscriptBox[box_{1},box_{2},box_{3}] |

box_{1}\&box_{2} | OverscriptBox[box_{1},box_{2}] |

box_{1}\+box_{2} | UnderscriptBox[box_{1},box_{2}] |

box_{1}\+box_{2}\%box_{3} | UnderoverscriptBox[box_{1},box_{2},box_{3}] |

box_{1}\/box_{2} | FractionBox[box_{1},box_{2}] |

\@box | SqrtBox[box] |

\@box_{1}\%box_{2} | RadicalBox[box_{1},box_{2}] |

form\` box | FormBox[box,form] |

\*input | construct boxes from input |

*Mathematica* requires that any input forms you give for boxes be enclosed within and . But within these outermost and you can use additional and to specify grouping.

In[10]:= |

Out[10]//DisplayForm= | |

In[11]:= |

Out[11]//DisplayForm= | |

In[12]:= |

Out[12]//DisplayForm= | |

In[13]:= |

Out[13]= |

When you type as input to *Mathematica*, the first thing that happens is that , , and are recognized as being separate "tokens". The same separation into tokens is done when boxes are constructed from input enclosed in . However, inside the boxes each token is given as a string, rather than in its raw form.

In[14]:= |

Out[14]//FullForm= | |

In[15]:= |

Out[15]//FullForm= | |

In[16]:= |

Out[16]//FullForm= | |

*Mathematica*expression.

In[17]:= |

Out[17]//FullForm= | |

Within sequences, you can set up certain kinds of boxes by using backslash notations such as and . But for other kinds of boxes, you need to give ordinary *Mathematica* input, prefaced by .

In[18]:= |

Out[18]//DisplayForm= | |

In[19]:= |

Out[19]//DisplayForm= | |

in effect acts like an escape: it allows you to enter ordinary *Mathematica* syntax even within a sequence. Note that the input you give after a can itself in turn contain sequences.

In[20]:= |

Out[20]//DisplayForm= | |

\!\(input\) | interpret input in the current form |

\!\(form\`input\) | interpret input using the specified form |

Controlling the way input is interpreted.

In[21]:= |

Out[21]= |

In[22]:= |

Out[22]= |

When you copy the contents of a cell from a notebook into a program such as a text editor, no explicit backslash backquote sequence is usually included. But if you expect to paste what you get back into a cell of a different type from the one it came from, then you will typically need to include a backslash backquote sequence in order to ensure that everything is interpreted correctly.