Wolfram Research

Function Repository Resource:

SymbolToSubscript (1.0.0) current version: 3.0.0 »

Source Notebook

Convert symbols into subscript forms

Contributed by: E. Chan-López & Jaime Manuel Cabrera  |  Ramón Eduardo Chan López

ResourceFunction["SymbolToSubscript"][expr]

gives the representation with subscripts for one or more unprotected symbols expr.

Details

ResourceFunction["SymbolToSubscript"] does not act on numbers, it just returns them.
ResourceFunction["SymbolToSubscript"] does not act on symbols that already have subscripts, it just returns them.
ResourceFunction["SymbolToSubscript"] does not act on protected heads of functions.
ResourceFunction["SymbolToSubscript"][expr,"MultipleIndices"] can be used on matrices and arrays, where it separates numbers with commas.

Examples

Basic Examples (2) 

Applying SymbolToSubcript for one unprotected symbol:

In[1]:=
ResourceFunction["SymbolToSubscript"][x1]
Out[1]=

Applying SymbolToSubcript to a list of unprotected symbols:

In[2]:=
ResourceFunction["SymbolToSubscript"][{x1, x2}]
Out[2]=
In[3]:=
ResourceFunction["SymbolToSubscript"][{x1[t], x2[t]}]
Out[3]=
In[4]:=
ResourceFunction["SymbolToSubscript"][{x\[Alpha][t], x\[Beta][t]}]
Out[4]=

Scope (3) 

Applying SymbolToSubscripts to a list of functions with protected heads:

In[5]:=
ResourceFunction["SymbolToSubscript", ResourceVersion->"1.0.0"][{Sin[t], Cos[x], Tan[s], Cot[x1], BesselJ[0, x1[t] + x2[t]], Csch[(x^(m - 2) - x3) (x^(n + 1) + x2)]}]
Out[5]=

Indexed for symbolic matrices:

In[6]:=
A = {{x11, x12}, {x21, x22}};
MatrixForm@
   ResourceFunction["SymbolToSubscript"][#, "MultipleIndices"] &@A
Out[7]=

Both the base and subscript in the output are symbols and inherit any existing definitions:

In[8]:=
y = 3; z = 5;
In[9]:=
ResourceFunction[<|"SymbolName" -> "FunctionRepository`$44e0e257606b4d13b22d7ab233ff8c7c`SymbolToSubscript", "UUID" -> "099e3da4-67d4-45dc-87d3-311a57425884", "ResourceType" -> "Function", "Name" -> InterpretationBox[
TagBox[
FrameBox[
PaneBox[
GridBox[{{
StyleBox[
StyleBox[
AdjustmentBox[
             "\"[\[FilledSmallSquare]]\"", BoxBaselineShift -> -0.25, BoxMargins -> {{0, 0}, {-1, -1}}], "ResourceFunctionIcon", FontColor -> RGBColor[
              0.8745098039215686, 0.2784313725490196, 0.03137254901960784]], ShowStringCharacters -> False, FontFamily -> "Source Sans Pro Black", FontSize -> 0.65 Inherited, FontWeight -> "Heavy", PrivateFontOptions -> {"OperatorSubstitution" -> False}], StyleBox[
RowBox[{
StyleBox[
              "\"SymbolToSubscript\"", "ResourceFunctionLabel", FontFamily -> "Source Sans Pro"], " "}], ShowAutoStyles -> False, ShowStringCharacters -> False, FontSize -> 0.9 Inherited, FontColor -> GrayLevel[0.1]]}},
          GridBoxSpacings -> {"Columns" -> {{0.25}}}], Alignment -> Left, BaseStyle -> {LineSpacing -> {0, 0}, LineBreakWithin -> False},
         BaselinePosition -> Baseline, FrameMargins -> {{3, 0}, {0, 0}}], Background -> RGBColor[0.968627, 0.976471, 0.984314], BaselinePosition -> Baseline, DefaultBaseStyle -> {}, FrameMargins -> {{0, 0}, {1, 1}}, FrameStyle -> RGBColor[0.831373, 0.847059, 0.85098], RoundingRadius -> 4], {"FunctionResourceBox", 
RGBColor[0.8745098039215686, 0.2784313725490196, 0.03137254901960784],
        "SymbolToSubscript"}, TagBoxNote -> "FunctionResourceBox"], 
ResourceFunction["SymbolToSubscript"], BoxID -> "SymbolToSubscript", Selectable -> False], "ShortName" -> InterpretationBox[
TagBox[
FrameBox[
PaneBox[
GridBox[{{
StyleBox[
StyleBox[
AdjustmentBox[
             "\"[\[FilledSmallSquare]]\"", BoxBaselineShift -> -0.25, BoxMargins -> {{0, 0}, {-1, -1}}], "ResourceFunctionIcon", FontColor -> RGBColor[
              0.8745098039215686, 0.2784313725490196, 0.03137254901960784]], ShowStringCharacters -> False, FontFamily -> "Source Sans Pro Black", FontSize -> 0.65 Inherited, FontWeight -> "Heavy", PrivateFontOptions -> {"OperatorSubstitution" -> False}], StyleBox[
RowBox[{
StyleBox[
              "\"SymbolToSubscript\"", "ResourceFunctionLabel", FontFamily -> "Source Sans Pro"], " "}], ShowAutoStyles -> False, ShowStringCharacters -> False, FontSize -> 0.9 Inherited, FontColor -> GrayLevel[0.1]]}},
          GridBoxSpacings -> {"Columns" -> {{0.25}}}], Alignment -> Left, BaseStyle -> {LineSpacing -> {0, 0}, LineBreakWithin -> False},
         BaselinePosition -> Baseline, FrameMargins -> {{3, 0}, {0, 0}}], Background -> RGBColor[0.968627, 0.976471, 0.984314], BaselinePosition -> Baseline, DefaultBaseStyle -> {}, FrameMargins -> {{0, 0}, {1, 1}}, FrameStyle -> RGBColor[0.831373, 0.847059, 0.85098], RoundingRadius -> 4], {"FunctionResourceBox", 
RGBColor[0.8745098039215686, 0.2784313725490196, 0.03137254901960784],
        "SymbolToSubscript"}, TagBoxNote -> "FunctionResourceBox"], 
ResourceFunction["SymbolToSubscript"], BoxID -> "SymbolToSubscript", Selectable -> False], "Description" -> "Given one or more unprotected symbols, obtain its representation with subscripts", "FunctionLocation" -> CloudObject[
    "https://www.wolframcloud.com/obj/resourcesystem/marketplacestorage/submissions/4d052d0bc026e682/1d2/1d262834-a420-4ab5-898e-ee7430716fe2/159c4f70b635db4f/data"]|>][yz]
Out[9]=

Applications (3) 

Format a symbolic polynomial:

In[10]:=
Polynomial[var_Symbol, coeff_Symbol, n_Integer?NonNegative] := Total[Array[
   Times[ToExpression[
      ToString[coeff] <> ToString[FromDigits[{n - ##}]]], var^#] &, n + 1, 0]]
In[11]:=
Column[MapAt[ResourceFunction["SymbolToSubscript"], ConstantArray[Polynomial[x, a, 5], 2], {2}], Spacings -> 0.75]
Out[11]=

Format a symbolic matrix:

In[12]:=
Matrix[symbol_Symbol, {row_Integer?Positive, column_Integer?Positive}] :=
 ToExpression[
  Array[ToString[symbol] <> ToString[#1] <> ToString[#2] &, {row, column}]]
In[13]:=
Row[Map[MatrixForm, MapAt[ResourceFunction["SymbolToSubscript"], ConstantArray[Matrix[x, {5, 5}], 2], {2}]], " "]
Out[13]=

Using MultipleIndices option for symbolic matrices:

In[14]:=
Row[Map[MatrixForm, MapAt[ResourceFunction["SymbolToSubscript"][#, "MultipleIndices"] &,
    ConstantArray[Matrix[x, {12, 12}], 2], {2}]], " "]
Out[14]=
In[15]:=
Row[Map[MatrixForm, MapAt[ResourceFunction["SymbolToSubscript"][#, "MultipleIndices"] &,
    ConstantArray[Matrix[x, {5, 5}], 2], {2}]], " "]
Out[15]=

Using :

In[16]:=
TeXForm@MatrixForm@
    ResourceFunction["SymbolToSubscript"][#, "MultipleIndices"] &@
 Matrix[x, {5, 5}]
Out[16]=

Using :

In[17]:=
Needs["MaTeX`"]
In[18]:=
MaTeX[MatrixForm@
    ResourceFunction["SymbolToSubscript"][#, "MultipleIndices"] &@
  Matrix[x, {5, 5}], Magnification -> 1.2]
Out[18]=

Define a function for making a Vandermonde matrix:

In[19]:=
VandermondeMatrix[symbol_Symbol, n_Integer?Positive] := Map[ToExpression, Array[(ToString[symbol] <> ToString[#1])^(#2 - 1) &, ConstantArray[n, 2]], {-1}]

Format a Vandermonde matrix:

In[20]:=
Row[Map[MatrixForm, MapAt[ResourceFunction["SymbolToSubscript"], ConstantArray[VandermondeMatrix[x, 5], 2], {2}]], " "]
Out[20]=

The SymbolToSubscript command allows to be used correctly when we have expressions with subscripts that are written as symbols:

In[21]:=
MatrixForm@VandermondeMatrix[x, 5]
Out[21]=
In[22]:=
Factor@Det[VandermondeMatrix[x, 5]]
Out[22]=
In[23]:=
TeXForm@MatrixForm@
  ResourceFunction["SymbolToSubscript"]@VandermondeMatrix[x, 5]
Out[23]=
In[24]:=
ResourceFunction["SymbolToSubscript"]@
 Factor@Det[VandermondeMatrix[x, 5]]
Out[24]=
In[25]:=
TeXForm@ResourceFunction["SymbolToSubscript"]@
  Factor@Det[VandermondeMatrix[x, 5]]
Out[25]=

Using :

In[26]:=
MaTeX[MatrixForm@
  ResourceFunction["SymbolToSubscript"]@VandermondeMatrix[x, 5], Magnification -> 1.2]
Out[26]=
In[27]:=
MaTeX[ResourceFunction["SymbolToSubscript"]@
  Factor@Det[VandermondeMatrix[x, 5]], Magnification -> 1.2]
Out[27]=

Possible Issues (1) 

Before getting the subscript format, SymbolToSubscript separates the expression x1y2 as {“x”,“1y2”}, and then passes each part to input form using ToExpression. Therefore, in the example x1y2 we get xy2 instead x1y2:

In[28]:=
ResourceFunction["SymbolToSubscript"][x1y2]
Out[28]=

Version History

  • 3.0.0 – 09 August 2023
  • 2.0.0 – 26 June 2023
  • 1.1.0 – 22 August 2022
  • 1.0.0 – 19 July 2022

Related Resources

License Information