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.
generates boxes without evaluating its input.
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
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
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
. 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 gplus
objects should be output in StandardForm
is now output using a subscripted
cannot however interpret this as input.
This tells Mathematica
to interpret a subscripted
as a specific piece of FullForm
Now the subscripted
is interpreted as a gplus
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.