Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

RE: Re: Constructing a Label

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93421] RE: [mg93399] Re: Constructing a Label
  • From: "Jose Luis Gomez" <jose.luis.gomez at itesm.mx>
  • Date: Fri, 7 Nov 2008 06:00:48 -0500 (EST)
  • References: <gepb15$sfr$1@smc.vnet.net> <200811060905.EAA15833@smc.vnet.net>

Dear Nikolaus

A string is a sequence of characters, however, a computer language can do
different things with those characters when printing.

For example, in the computer language "C", a string like this "Hello\nBye"
is printed in two lines, the "\n" characters are Not printed literary, they
create an action (a "carriage return"), therefore printing "Hello" in the
first line and "Bye" in the second line.

Well, "Mathematica" does the same as "C", there are some special
combinations of characters that are not printed literally, but they make
Mathematica perform a special action (for example, print a formatted
fraction or a formatted exponent)

See this part of Mathematica's documentation: 
http://reference.wolfram.com/mathematica/tutorial/StringRepresentationOfBoxe
s.html

Now, personally, I do Not like using strings or boxes (RowBox) directly. The
reason is that I have use them a lot, a lot, in the source code of my
package for doing Quantum Mechanics and Quantum Computing in Mathematica:
http://homepage.cem.itesm.mx/lgomez/quantum/ 

And, as I have use them a lot, I know they are very complex, very messy, and
it is very simple to create RowBox that "looks" (prints) perfectly right to
a human, yet it cannot be understood by Mathematica.

(If you are brave, download my Quantum package and take a look at the source
code in the Notation.m file. I bet you will be surprised by the huge amount
of nested RowBox commands I have to use to incorporate Quantum Dirac's
notation in Mathematica)

Now, any any any expression that you write or obtain in Mathematica uses
RowBox, but usually they use it in a way totally hidden to the final user,
totally transparent.

Therefore, Why use the difficult, low-level RowBox command? Better use a
higher-level command like HoldForm, etc. this command will generate the
proper RowBox commands for you, and you do Not have to worry about them or
their low-level (difficult) syntax. You do Not even have to know that RowBox
exists, yet Mathematica is using it in a transparent way.

So I vote for:

f[x_] := x^3;  
TraditionalForm[HoldForm[f[x]] == f[x]]


Best regards

Jose 

Mexico  





-----Mensaje original-----
De: Nikolaus Rath [mailto:Nikolaus at rath.org] 
Enviado el: Jueves, 06 de Noviembre de 2008 03:06
Para: mathgroup at smc.vnet.net
Asunto: [mg93399] Re: Constructing a Label

Nikolaus Rath <Nikolaus 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 there
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
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 majority.
  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




  • Prev by Date: Re: Re: Tooltip ans Sound - 2nd posting
  • Next by Date: Re: Re: Constructing a Label
  • Previous by thread: Re: Constructing a Label
  • Next by thread: Re: Constructing a Label