I simply want to be able to assign the subscript from something like Subscript[x, 1] to a new variable. How should I do this?

  • $\begingroup$ The question is not really clear. An example would help. $\endgroup$
    – wolfies
    Aug 1, 2021 at 23:24

2 Answers 2


If you have a variable

y=Subscript[x, 1]; 

then to extract the index it suffices to do


which in this case returns 1 as expected.

For more than one indices, this works

In[1]:= y=Subscript[x,1,2,3]
Out[1]= Subscript[x,1,2,3]

In[2]:= y[[2;;-1]]/.Subscript->List
Out[2]= {1,2,3}

For y with any number of subscripts ,

Rest[List @@ y]

also works. For instance

y = Subscript[x, 1, 2];
Rest[List @@ y]
(* {1, 2} *)

As a word of advice, use Subscript and the like for formatting expressions for display but not for symbolic computations, where it sometimes leads to problems.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.