Skip to main content

output formatting - Symbol with Subscript but no quotes in it!


If I use the following function to define me a fancy subscript:


Needs["Notation`"];
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]

SetAttributes[fancySubscript,HoldFirst]

fancySubscript[var_Symbol, tag_String, index_Integer] /;
Not[ValueQ[var]] := Subscript[var, tag <> ToString[index]]


fancySubscript[var_Symbol, tags : {_String ..}, index_Integer] /;
Not[ValueQ[var]] := fancySubscript[var, #, index] & /@ tags

fancySubscript[var_Symbol, tags : {_String ..}, indices : {_Integer ..}] /;
Not[ValueQ[var]] := fancySubscript[var, tags, #] & /@ indices

I can use the following now:


fancySubscript[b, {"b"}, Range@3]



$\left( \begin{array}{c} b_{\text{b1}} \\ b_{\text{b2}} \\ b_{\text{b3}} \\ \end{array} \right)$



With the notation module by symbolizing the subscripts: the values are now :


b\[UnderBracket]Subscript\[UnderBracket]DoubleQuote\[UnderBracket]b1\[UnderBracket]DoubleQuote

1. Problem
But when I want to refer to such a variable in the list above and write with the shortcuts in a cell by typing b then Ctrl+_ then 1.


The variable is a new symbol because i did not use Quotes ""


b\[UnderBracket]Subscript\[UnderBracket]b1


How can we circumvent this that I can still write all variables in the cell and they are parsed and interpreted as the one defined in the fancySubscript command?


It is not so easy because, when I would use something like this:


fancySubscript[b, {b}, Range@3]

I would get an infinite loop, because it is no more a string, hm...


2. Problem:


I cannot assign it back to the variable b:


 b=fancySubscript[b, {"b"}, Range@3]

This gives an infinite loop, but when I try this:



btemp=fancySubscript[b, {"b"}, Range@3]
b=btemp

This should work, and not give an inifinte loop, because btemp contains the new defined symbols and they should then be assigned to b again, but also here mathematica trys to run a recursion which I dont understand??




Comments