MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Question concerning MakeBoxes

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60420] Re: Question concerning MakeBoxes
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 16 Sep 2005 03:48:59 -0400 (EDT)
  • Organization: The University of Western Australia
  • References: <dg8loi$rf1$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <dg8loi$rf1$1 at smc.vnet.net>,
 Cca <cca at gregosetroianos.mat.br> wrote:

> 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

Note that you can use \[AutoRightMatch] instead of hiding the right "}".

> (As far as I know, the idea for this interesting and convenient "grid 
> notation" is due to Bruno BuchBerger, but this is another history.)

Perhaps there an implementation of this notation in Theorema then? See

  http://www.risc.uni-linz.ac.at/people/buchberg/theorema_project.html

> 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]?

I would expect that you could use the Notation package to do what you 
want more directly.

Cheers,
Paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Hamiltoncircuits on polyhedra
  • Next by Date: Re: Bug in Reduce?
  • Previous by thread: Re: Question concerning MakeBoxes
  • Next by thread: Nesting NMaximize