MathGroup Archive 2005

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

Search the Archive

Re: Avoiding parentheses in Formatted or box structures

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59651] Re: Avoiding parentheses in Formatted or box structures
  • From: "James Gilmore" <james.gilmore at yale.edu>
  • Date: Tue, 16 Aug 2005 04:39:31 -0400 (EDT)
  • Organization: Yale University
  • References: <ddpsvi$opu$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi David,

The problem here is that you are letting Mathematica use its internal 
procedures to specify the output. Just control the multiplication of a 
constant like you control the format of the 'f' function.

ClearAll[f]
Format[f[x_Symbol]] := SequenceForm[g, x]
Format[f[x^n_]] := SequenceForm[g, x^n]

constantmultiply[a_, f_] := SequenceForm[a, SequenceForm[" ", f]]

In[45]:=
{f[x], f[x^3]}
Out[45]=
{gx, gx^3}
In[46]:=
(constantmultiply[a, #1] & ) /@ %
Out[46]=
{a" "gx, a" "gx^3}

The required output. As a check:

In[53]:=
% /. a -> 5
Out[53]=
{5" "gx, 5" "gx^3}


Also, RowBox strucutres work:

In[77]:=
step1 = RowBox[{SubscriptBox["a", "1"], SubscriptBox["b", "2"]}]
DisplayForm[constantmultiply[k, %]]
Out[77]=
RowBox[{SubscriptBox[a, 1], SubscriptBox[b, 2]}]
Out[78]//DisplayForm=
\!\(\*
TagBox[
InterpretationBox[
RowBox[{"k", "\[InvisibleSpace]",
InterpretationBox[\(" "\[InvisibleSpace]\(\(a\_1\) b\_2\)\),
SequenceForm[ " ",
RowBox[ {
SubscriptBox[ "a", "1"],
SubscriptBox[ "b", "2"]}]],
Editable->False]}],
SequenceForm[ k,
SequenceForm[ " ",
RowBox[ {
SubscriptBox[ "a", "1"],
SubscriptBox[ "b", "2"]}]]],
Editable->False],
DisplayForm]\)


James Gilmore

Graduate Student
Department of Physics
Yale University
New Haven, CT 06520 USA

Email: james.gilmore at yale.edu
URL: http://pantheon.yale.edu/~jbg39/





"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)}
>
> 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/
> 



  • Prev by Date: Re: How to specify boundary conditions on all 4 sides of a plate for a steady state heat equation (PDE) using NDSolve? (Laplace equation)
  • Next by Date: Re: Linking to Mathematica Kernel from Excel
  • Previous by thread: Re: Avoiding parentheses in Formatted or box structures
  • Next by thread: Re: Avoiding parentheses in Formatted or box structures