I used to do this with Notation`Symbolize, but it had some shortcomings like, if you save expressions on disk and later load into another notebook, then symbolization is not preserved automatically, and you end up with lots of names with \[UnderBracket] in them. Even more important, you cannot create a list of symbolized indexed variables by just using Table[Subscript[x, j], {j, 10}]. I found a different approach, and so far it serves my needs pretty well.
Mathematica allows many Unicode characters in symbol names, including subscript digits ₀₁₂₃₄₅₆₇₈₉. So, I create indexed variables using these digits in symbol names, but because they are not easy to enter and they look in notebooks slightly different than regular subscripts, I format them as regular subscripted expressions using MakeBoxes, and use Subscript to create them on demand from regular subscripts. When I save expressions containing symbols with subscripts on disk, in the worst case they will be loaded as regular symbols with Unicode subscript digits in their names (e.g. x₁₂) that is still pretty readable.
The following code will automatically symbolize all subscripted symbols in Global` context:
With[{regular = CharacterRange["0", "9"],
subscripts = CharacterRange[8320, 8329]}, (* ₀₁₂₃₄₅₆₇₈₉ *)
With[{pat = Alternatives[subscripts],
toSub = Thread[regular -> subscripts],
fromSub = Thread[subscripts -> regular]},
$NewSymbol = Function[{name, ctx},
If[ctx === "Global`" && StringEndsQ[name, pat],
With[{len = StringPosition[name, pat][[1, 1]] - 1},
With[{s = StringTake[name, len],
index = StringReplace[StringDrop[name, len], fromSub]},
With[{ex = MakeExpression["Global`" <> name, StandardForm]},
ReleaseHold[Hold[
MakeBoxes[ex, StandardForm] :=
InterpretationBox[SubscriptBox[s, index], ex,
Editable -> True, AutoDelete -> True]]
/. HoldComplete[h_] :> h]]]]]];
SetAttributes[Subscript, HoldFirst];
Subscript[s_Symbol /; Context[Unevaluated[s]] === "Global`", j_Integer /; j >= 0] :=
ToExpression["Global`" <> SymbolName[Unevaluated[s]]
<> StringReplace[ToString[j], toSub]]]];
Please feel free to criticize or propose improvements.
Information(i.e.??) isHoldAllso it won't evaluateVar[[1]]to its contents. You could tryInformation[Evaluate[Var[[1]]]instead. More in general, however, when you assign values to subscripted variables, the value is actually associated with theSubscriptfunction, and not with the variable. – MarcoB Jan 23 '17 at 16:30Symbolizecommand then there will be no problem for assigning. :) – Hosein Rahnama Jan 23 '17 at 16:35Indexed, or simply use e.g.x[1, 3]instead of $x_{1,3}$. See e.g. (114632) and links, and search this site for "alternatives to Subscript". – MarcoB Jan 23 '17 at 16:39