Re: please explain why ToExpression[SubscriptBox["x","1"],StandardForm] ...
- To: mathgroup at smc.vnet.net
- Subject: [mg71852] Re: please explain why ToExpression[SubscriptBox["x","1"],StandardForm] ...
- From: "Andrew Moylan" <andrew.j.moylan at gmail.com>
- Date: Fri, 1 Dec 2006 06:21:59 -0500 (EST)
- References: <ekmdup$8bq$1@smc.vnet.net>
Hi Chris, I can't immediately see what's wrong with your code. For your interest, here's the code of my personal SubscriptSymbols` package that I use all the time to make all subscripts behave like symbols. Unlike the Utilities`Notation` package, it works just fine in batch mode too, which is the reason I wrote it: BeginPackage["SubscriptSymbols`"]; Begin["`Private`"]; SubscriptToProxySymbol[_] = Null; MakeExpression[SubscriptBox[a_, b_], StandardForm] := Module[{proxy, boxes = SubscriptBox[a, b]}, proxy = SubscriptToProxySymbol[boxes]; If[proxy === Null, proxy = ToString[Unique[SubscriptSymbolsProxySymbol]]; SubscriptToProxySymbol[boxes] = proxy; With[{n = Symbol[proxy]}, MakeBoxes[n, StandardForm] := boxes]; ]; MakeExpression[RowBox[{proxy} ] ] ] End[]; EndPackage[]; Cheers, Andrew On Nov 30, 10:06 pm, "Chris Chiasson" <c... at chiasson.name> wrote: > fails when the definition > > MakeExpression[SubscriptBox["x","1"],___]=dog; > > is active. > > I think it is related to the output of > > BoxForm`TopLevelMakeExpression[StripBoxes[SubscriptBox["x","1"]],StandardForm] > > being > > ErrorBox[dog]. > > If you can answer that, then I may be able to make my solution to > " Using subscripts in function-parameter names" work... here > is what I have so far: > > Unprotect[SubscriptBox]; > With[{usc=FromCharacterCode[63316]}, > subscriptAsSymbol[symb_Symbol]:= > With[{symbStr=ToString@symb}, > SubscriptBox/: > MakeExpression[SubscriptBox[symbStr,scriptStrs__String],format_]:= > MakeExpression[SubscriptBox[symbStr,scriptStrs],format]= > With[{symbWithSub= > ToExpression[ > ToString@ > BoxForm`Intercalate[SequenceForm[symbStr,scriptStrs], > usc],format]}, > MakeBoxes[symbWithSub,_]=SubscriptBox[symbStr,scriptStrs]; > symbWithSub]]]; > subscriptAsSymbol@x; > ToExpression[SubscriptBox["x","1"],StandardForm] > > --http://chris.chiasson.name/