Question concerning MakeBoxes
- To: mathgroup at smc.vnet.net
- Subject: [mg60378] Question concerning MakeBoxes
- From: Cca <cca at gregosetroianos.mat.br>
- Date: Wed, 14 Sep 2005 03:27:58 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Let's start a new Mathematica (5.1) session and note that
FormatValues[And]
is the empty list. I want to define a rule for formatting logical
conjunctions and disjunctionsin in such a way that, for example,
the conjunction
p&&q&&r
is formatted in TraditionalForm as
RowBox[{"\[And]",
RowBox[{StyleBox["{",SpanMaxSize->\[Infinity]],
GridBox[{{"p"},{"q"},{"r"}},ColumnAlignments->{Left}],
StyleBox["}",ShowContents->False]}]," "}]//DisplayForm
(As far as I know, the idea for this interesting and convenient "grid notation" is due to
Bruno BuchBerger, but this is another history.)
For me, one obvious solution to this problem should be something like
Unprotect[And];
And/:MakeBoxes[And[c__],TraditionalForm]:=
RowBox[{"\[And]",
RowBox[{StyleBox["{",SpanMaxSize->\[Infinity]],
GridBox[{#}&/@(MakeBoxes[#,TraditionalForm]&/@{c}),
ColumnAlignments->{Left}],
StyleBox["}",ShowContents->False]}]," "}];
Protect[And];
In fact,
p&&q&&r//TraditionalForm
is now displayed as intended. However, it works only once: evaluating again
p&&q&&r//TraditionalForm
gives the built-in traditional formatting. After inspecting
FormatValues[And]
we see what is going on: my formatting rule is the LAST on the list. So, in order to
force Mathematica to apply my definition first, I evaluate
Unprotect[And];
FormatValues[And]=Reverse@FormatValues[And];
Protect[And];
This solves my problem, but in a somewhat inelegant way.
My questions are:
(1) what is the explanation for this behavior?
(2) how can I get the intended result without reversing FormatValues[And]?
My anticipated thanks for any help.
Carlos César de Araújo
Gregos & Troianos Educacional
www.gregosetroianos.mat.br
Belo Horizonte, MG, Brazil
(31) 3283-1122