Re: Why HoldForm[] shows this expression in red in notebook?

*To*: mathgroup at smc.vnet.net*Subject*: [mg125081] Re: Why HoldForm[] shows this expression in red in notebook?*From*: "Nasser M. Abbasi" <nma at 12000.org>*Date*: Tue, 21 Feb 2012 06:08:52 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <jhqml4$f9t$1@smc.vnet.net> <jhsu1o$nmq$1@smc.vnet.net>*Reply-to*: nma at 12000.org

On 2/20/2012 1:51 AM, David Bailey wrote: > On 19/02/2012 11:32, Nasser M. Abbasi wrote: >> foo[x_, v_] := Module[{z = v}, >> {x^z, Hold[x^z], HoldForm[x^z]} >> ]; >> >> Any one knows why the notebook shows the 'z' in the last term above in >> the red and but not the other z's? >> >> I am using V 8.04 on windows >> >> thanks >> --Nasser >> >> > I think the last z is coloured red because you are returning an > expression involving a local variable: > But we return expressions involving local variables all the time? foo[] := Module[{x}, x + 3 ] no red color any where. > In[2]:= foo[a,b] > > Out[2]= {a^b,Hold[a^z$6385],a^z$6385} > > Notice the strange variable z$6385 - which is local. I can't see why the > middle term isn't red as well, but the left term evaluates to something > that doesn't involve a local variable. > > Perhaps you really wanted to write this: > > foo[x_, v_] := Module[{z = v}, > {x^z, Hold[Evaluate[x^z]], HoldForm[Evaluate[x^z]]} > ]; No, that would not work for me, may be I should explain more: I have an internal function, where I want to make a plot, and want to make a plot label for the plot. The plot label will be an analytical expression of the equation solved. I am not supposed to use Strings to formulate the equations for labels. So what other options are there? The way I do things now is to make labels using this method: Text@Row[{"equation ",Style[TraditionalForm[HoldForm[...]]]}] And in place of ... I write the equation, using standard Mathemtica code, as I would write it in the main cell itself as code. i.e. no strings. For example, to render this equation: u''[x]=f(x), I would write Text@Row[{"equation ", Style[TraditionalForm[HoldForm[u''[x] == f[x, y]]]]}] I do not want to Evaluate u''[x] ofcourse. I want just to display the equation itself as is. The problem comes when I do the above inside a function, which already has x and y as local symbols being used, like this: foo[] := Module[{x, y}, x = 1; y = 2; {Text@Row[{"equation is ", Style[TraditionalForm[HoldForm[u''[x] == f[x, y]]]]}] } ] Now the red comes back and the $$ show up in the label which ofcourse I do not want. So, I have to change the code in the function, which already uses these symbols to use someother symbols. not good. Again, I can't use strings to make up the equation in the label. So, what else is one to do? What is the canonical way to do this sort of thing in Mathematica, without using strings? Something else better than HoldForm around to use? I do not want to use global symbols. I like to render an expression from inside a function using TraditionalForm and have the freedom to use any Mathematica symbol, like \[Del], and others as well. Since I am using HoldForm, I thought I could do that. thanks, --Nasser