I have stumbled over several issues about subscripted symbols recently. I would like that I can enter subscripted variables with my keyboard and that they are treated as symbols. I would also like to have lists (matrices) of these subscripted symbols and that they are formatted in the output nicely so that I can do calculations which them and still be able to see the nice output.
So far I have come up with the following (which uses the Notation Package):
Needs["Notation`"]; Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]] Symbolize[ParsedBoxWrapper[SubsuperscriptBox["_", "_", "_"]]] makeSpecialSymb[var_String, i_, j_] := ToExpression[SubscriptBox[var, ToString[i], ToString[j]]]; makeSpecialSymb[var_SubscriptBox, i_, j_] := ToExpression[ SubscriptBox[var[[1]], var[[2]] <> "," <> ToString[i] <> "," <> ToString[j]]]; makeSpecialSymb[var_SubsuperscriptBox, i_, j_] := ToExpression[ SubsuperscriptBox[var[[1]], var[[2]] <> "," <> ToString[i] <> "," <> ToString[j], var[[3]] ]]; SymbolicMatrix[func_Function, m_Integer, n_Integer] := Table[func[i, j], {i, 1, m}, {j, 1, n}]; SymbolicMatrix[func_Function, m_Integer] := Table[func[i], {i, 1, m}, {j, 1, 1}]; SymbolicMatrix[argSpecSymb_, m_Integer, n_Integer] := Table[makeSpecialSymb[argSpecSymb, i, j], {i, 1, m}, {j, 1, n}]; SymbolicMatrix[argSpecSymb_, m_Integer] := Table[makeSpecialSymb[argSpecSymb, i], {i, 1, m}, {j, 1, 1}]; So i can do the following:
A = Map[HoldForm, SymbolicMatrix["W", 2, 2], 2]; B = SymbolicMatrix[SubsuperscriptBox["G", "S", "k"], 2, 2] ; A // FullForm B // MatrixForm ?"Global`*" 
So everything works fine, I can make a Matrix out of Symbols which are defined in the global context and which get formatted really nice. This is cool!
Another approach would be something (from Mike), where we do not generate the symbols but rather use some sort of formatting expression like the following:
ClearAll[fancySubscript1]; SetAttributes[fancySubscript1, HoldFirst] fancySubscript1 /: MakeBoxes[fancySubscript1[var_, index_], StandardForm] := SubscriptBox[MakeBoxes[var, StandardForm], StyleBox[RowBox[{MakeBoxes[var, StandardForm], MakeBoxes[index, StandardForm]}], ZeroWidthTimes -> True]] fancySubscript1[var_, indices : {_Integer ..}] := fancySubscript1[var, #] & /@ indices fancySubscript[H, {{1, 2}, {3, 4}}] Which gives: 
If I would go with this method, which prints all values very nicely, I can make matrices which do not contain symbols but rather function expression. In this method I am probably also much more flexible when I want to define my own look how the individual fancySubscripts are formatted.
Which version would you go for in which cases? I am a bit unsure, which one of these is better to use, also with respect to flexibility. Also with respect to what method is better to use for if I want to replace the variables with values in subsequent calculations (either by replacement rules or by Set[] ) ?
Another question for method 1, how does mathematica decide how to display my crazy named variables like: W\[UnderBracket]Subscript\[UnderBracket]1 in the output? It seems that all symbols, which get created by the ParsedBoxWrapper which I think gets called when ever it sees a SubscriptBox pattern as defined in the Symbolize command, are displayed nicely. If I enter RR\[UnderBracket]Subscript\[UnderBracket]100 in a new notebook it does not immediately get converted to a nice subcripted output format? Whats the problem here?
I would be really interessted what the caveats are in these two methods, because I am not kind of a hero with mathematica.
Thanks!
$PreReadparse your custom notations and interprets your custom symbols before sending to the kernel. If your code generates a subscripted expression in the kernel, then$PreReaddoesn't have a chance to convert it before the kernel passes it on to the next function. Similarly, I think$PrePrintconverts the crazy named variables into your pretty notation. $\endgroup$Symbolizethe rules are added to the$PreReadand$PrePrintdefinitions, so the crazy names that you enter directly don't get caught by theSymbolizepattern, so the$PreReadand$PrePrintrules don't get created. $\endgroup$