Re: Avoiding parentheses in Formatted or box structures
- To: mathgroup at smc.vnet.net
- Subject: [mg59664] Re: Avoiding parentheses in Formatted or box structures
- From: "Carl K. Woll" <carlw at u.washington.edu>
- Date: Tue, 16 Aug 2005 05:39:25 -0400 (EDT)
- Organization: University of Washington
- References: <ddpsvi$opu$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"David Park" <djmp at earthlink.net> wrote in message news:ddpsvi$opu$1 at smc.vnet.net... > I'm producing some formatted output. The following is a simplified version > that illustrates the problem I am having. > > ClearAll[f] > Format[f[x_Symbol]] := SequenceForm[g, x] > Format[f[x^n_]] := SequenceForm[g, x^n] > > The first line of output is what I desire. No extra parentheses. But when > we multiply these expressions by a constant we obtain an extra set of > parentheses, which I don't want. > > {f[x], f[x^3]} > a % > > {gx, gx^3} > {a (gx), a (gx^3)} > David, It looks like this is a good place to use TagBox: f /: MakeBoxes[f[x_], form_] := TagBox[MakeBoxes[SequenceForm[g, x], form], f, SyntaxForm -> "\[CircleDot]"] The SyntaxForm option to TagBox causes it to have the precedence of \[CircleDot], which is higher than Times. In your example, we now have no parentheses: In[9]:= {f[x], f[x^3]} a % Out[9]= {g\[InvisibleSpace]x,g\[InvisibleSpace]x^3} Out[10]= {a g\[InvisibleSpace]x,a g\[InvisibleSpace]x^3} > So I tried the following Format statements. > > ClearAll[f] > f[x_Symbol] := g\[InvisibleApplication]x > f[(x_)^(n_)] := g\[InvisibleApplication](x^n) > > Now I don't get parentheses when I multiply the expression by a constant, > but I do get them after the g. The InvisibleApplication does not carry > through. > > {f[x], f[x^3]} > a% > > {g[x],g[x^3]} > {a g[x], a g[x^3]} > > I want > > {gx, gx^3} > {a gx, a gx^3} > > Is it possible to obtain that? I've also tried RowBox structures without > success. The example in the Book on RowBox, for example, produces an extra > set of parentheses when multiplied by a constant. > > step1 = RowBox[{SubscriptBox["a", "1"], SubscriptBox["b", "2"]}] // > DisplayForm > k step1 > > David Park > djmp at earthlink.net > http://home.earthlink.net/~djmp/ > Carl Woll Wolfram Research