Re: Why HoldForm[] shows this expression in red in notebook?
- To: mathgroup at smc.vnet.net
- Subject: [mg125127] Re: Why HoldForm[] shows this expression in red in notebook?
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Thu, 23 Feb 2012 05:45:41 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jhqml4$f9t$1@smc.vnet.net> <jhsu1o$nmq$1@smc.vnet.net> <jhvu1f$7ua$1@smc.vnet.net>
On 21/02/2012 11:09, Nasser M. Abbasi wrote: > 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 > ] I think the syntax colourer just fails to recognise what is going on here. It is not fool proof. > > no red color any where. > > > 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. I'd say the simplest answer is to use global variables inside a Block construct instead of a Module construct. David Bailey http://www.dbaileyconsultancy.co.uk