# Simplistic Notation example

Notation package looks poorly documented.

For example, GridBoxDividers option is not documented at all.

Can someone give me a simplistic example of a Notation set up? For example, suppose I wish to represent

as

$\frac{a}{b}$

with

GridBox[{{"a"}, {"b"}}, GridBoxDividers -> {"Rows" -> {{False, True}}}]

If I enter

Notation[GridBox[{{ToString[x_]}, {ToString[y_]}},
GridBoxDividers -> {"Rows" -> {{False, True}}}]
\[DoubleLongLeftRightArrow]

I get an error

Notation::noexbtag: The external representation GridBox[{{x_},{y_}},GridBoxDividers->{Rows->{{False,True}}}] does not have an embedded TemplateBox with tag NotationTemplateTag. The Notation statement Notation[GridBox[{{x_},{y_}},GridBoxDividers->{Rows->{{<<2>>}}}][DoubleLongLeftRightArrow]MyHead[x_,y_]] may not have been entered using the palette, or the embedded TemplateBox may have been deleted. The embedded TemplateBox ensures correct parsing and retention of proper styling and grouping information. >>

-

Some people make good use of the Notation package but I have never been very successful with it. A good reason to learn a little about MakeBoxes and TemplateBox.

The following MakeBoxes definition will format your expression.

form : (StandardForm | TraditionalForm) : StandardForm] :=
InterpretationBox[#1, #2] & @@ {GridBox[{{MakeBoxes[a,
form]}, {MakeBoxes[b, form]}},
GridBoxDividers -> {False, {{False, True}}}], MyHead[a, b]}

The InterpretationBox's arguments are held so using the trick of making it a pure function and applying it to a List allows you compute the format if necessary. The list could be generated by an extended Module calculation. The first item in the list is the formatted expression and the second is the internal expression, the same as the initial expression. The following should then work.

MyHead[5 x + 3, 2 x - 1]

One disadvantage of this is that the output can be copied and pasted but not edited.

An alternative approach uses TemplateBox, which is a documented function in Version 9.

form : (StandardForm | TraditionalForm) : StandardForm] :=
Module[{dispFunc},
dispFunc =
GridBox[{{#1}, {#2}},
GridBoxDividers -> {False, {{False, True}}}] &;