Re: Constructing a Label
- To: mathgroup at smc.vnet.net
- Subject: [mg93444] Re: Constructing a Label
- From: magma <maderri2 at gmail.com>
- Date: Sat, 8 Nov 2008 03:59:45 -0500 (EST)
- References: <gepb15$sfr$1@smc.vnet.net> <24955424.1225964460341.JavaMail.root@m02>
On Nov 7, 12:01 pm, "David Park" <djmp... at comcast.net> wrote: > f[x_] := 2/3 Sin[x^2]; > > I would consider the first method to be the best: > > Row[{"f[x] = ", f[x]}] > > This is because it is the most direct and intuitive. The second method > involves descending in to box structure programming, which the new featur= es > of Version circumvent. > > The third method with HoldForm is also ok, but if f is define within a > Module with f being a Module variable, then you won't like the result > because it won't be a simple 'f'. > > The StringForm method is a nice trick, but it is not as versatile or > intuitive as the Row method. > > The last method is too arcane and too old fashioned. ToString, by default= , > formats to the old OutputForm, which uses multiple lines for the 3D form = of > expressions. That's why you have to specify TraditionalForm or StandardFo= rm. > If you look at the FullForm of the ToString expression you will see that > Mathematica uses the lower level specification for boxed structures: > > ToString[TraditionalForm[f[x]]] // FullForm > "\!\(TraditionalForm\`\(2\\ \(\(sin(\(\(x\^2\)\))\)\)\)\/3\)" > > Using Column and Row to build up displays is a nice new method in Version= 6 > and it's worthwhile getting to know how to use them. > > David Park > djmp... at comcast.nethttp://home.comcast.net/~djmpark > > From: Nikolaus Rath [mailto:Nikol... at rath.org] > > Nikolaus Rath <Nikol... at rath.org> writes: > > Hello, > > > I want to automatically construct labels of the form > > "A = <value of A>" for a number of plots. > > > However, I cannot quite figure out how to generate the above > > expression. > > I have now received quite a number of different solutions for this > problem (now for some general function f[x]): > > f[x_] := 2/3 Sin[x^2]; > Row[{"f[x] = ", f[x]}] > DisplayForm[RowBox[{"f[x] = ", f[x]}]] > HoldForm[f[x]] == f[x] > StringForm["f[x] = ``", f[x]] > "f[x] = " <> ToString[TraditionalForm[f[x]]] > > While they all seem to work equally well for my problem, I do not > quite understand how the last two expressions can actually work out. I > thought that a String is just a sequence of unicode characters, so how > is it possible that it renders as true fraction? > > Moreover, this really made me curious in which way the above > expressions differ. The only difference that I found when evaluating > them is that the last one (obviously) only renders in traditional form > and that HoldForm only works if I use == instead of =. But are ther= e > other differences? An should I prefer some variant over the others? > > Personally, the variant with HoldForms seems most natural to me, > because it directly expresses what I want to do ("print f[x] in If you are not interested in Traditional form, then either the Holdform or the Row example are good, but if you like to use Traditional form, I would suggest Row[{HoldForm[f[x]], " = ", f[x]}] // TraditionalForm which is simple enough and replicates as much as possible standard high quality printouts. hth > evaluated and unevaluated form"). > > I'd be interested in hearing other opinions about this. > > Best, > > -Nikolaus > > -- > =C2=BBIt is not worth an intelligent man's time to be in the major= ity. > By definition, there are already enough people to do that.=C2=AB > = -J.H. Hardy > > PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C