Low-Level Input and Output Rules

MakeBoxes[expr,form]construct boxes to represent expr in the specified form
MakeExpression[boxes,form]construct an expression corresponding to boxes

Low-level functions for converting between expressions and boxes.

MakeBoxes generates boxes without evaluating its input.
In[1]:=
Click for copyable input
Out[1]=
MakeExpression interprets boxes but uses HoldComplete to prevent the resulting expression from being evaluated.
In[2]:=
Click for copyable input
Out[2]=

Built into Mathematica are a large number of rules for generating output and interpreting input. Particularly in StandardForm, these rules are carefully set up to be consistent, and to allow input and output to be used interchangeably.

It is fairly rare that you will need to modify these rules. The main reason is that Mathematica already has built-in rules for the input and output of many operators to which it does not itself assign specific meanings.

Thus, if you want to add, for example, a generalized form of addition, you can usually just use an operator like for which Mathematica already has built-in input and output rules.

This outputs using the operator.
In[3]:=
Click for copyable input
Out[3]=
Mathematica understands on input.
In[4]:=
Click for copyable input
Out[4]//FullForm=

In dealing with output, you can make definitions for Format[expr] to change the way that a particular expression will be formatted. You should realize, however, that as soon as you do this, there is no guarantee that the output form of your expression will be interpreted correctly if it is given as Mathematica input.

If you want to, Mathematica allows you to redefine the basic rules that it uses for the input and output of all expressions. You can do this by making definitions for MakeBoxes and MakeExpression. You should realize, however, that unless you make such definitions with great care, you are likely to end up with inconsistent results.

This defines how objects should be output in StandardForm.
In[5]:=
Click for copyable input
is now output using a subscripted .
In[6]:=
Click for copyable input
Out[6]=
Mathematica cannot, however, interpret this as input.
This tells Mathematica to interpret a subscripted as a specific piece of FullForm input.
In[8]:=
Click for copyable input
Now the subscripted is interpreted as a .
In[9]:=
Click for copyable input
Out[9]//FullForm=

When you give definitions for MakeBoxes, you can think of this as essentially a lower-level version of giving definitions for Format. An important difference is that MakeBoxes does not evaluate its argument, so you can define rules for formatting expressions without being concerned about how these expressions would evaluate.

In addition, while Format is automatically called again on any results obtained by applying it, the same is not true of MakeBoxes. This means that in giving definitions for MakeBoxes you explicitly have to call MakeBoxes again on any subexpressions that still need to be formatted.

• Break input into tokens.
• Strip spacing characters.
• Construct boxes using built-in operator precedences.
• Strip StyleBox and other boxes not intended for interpretation.
• Apply rules defined for MakeExpression.

Operations done on Mathematica input.

New to Mathematica? Find your learning path »
Have a question? Ask support »