# Is there a way to use a subscript as variable? [duplicate]

I'm really new with Mathematica, and I could not find a previously question similar to this one.

Is there a way that Mathematica can be made to recognize and treat a subscript letter as variable so that I could write equations like:

$$\qquad a_{n} = n + 1$$

and have the evaluation of $$a_{5}$$ return 6.

Note: I'm actually trying to write equation for commutators like $$[L_n,\, L_m] = n - m$$

• You can do it now, but problems occasionally occur. Consider, for instance, a[n] instead. – bbgodfrey Sep 6 '19 at 1:09
• Possible duplicate of Can we use letter with a subscript as a variable in Mathematica? Also see An alternative to subscripts? and Basic syntax issues (point #3). – WReach Sep 6 '19 at 4:43
• @WReach I'm afraid OP's question isn't a duplicate of that one. Though OP mentions "variable" in his post, according to the formula, OP is probably looking for something like Subscript[a, n_] = n + 1. – xzczd Sep 6 '19 at 7:29
• Such a functional assignment would require the redefinition of Subscript which will SURELY cause unwanted troubles elsewhere in Mathematica where subscripts are intended to use with no underlying definition. Modifying built-in symbols is not advised. On the other hand, you can make a[n] to format as a subscripted symbol that is still interpretable as a[n] or to whatever it evaluates due to its definition. – István Zachar Sep 6 '19 at 10:22

I would strongly recommend not using Subscript. One should think of Subscript as a typographical construct (which can be abused to use subscripting of a variable). Better is to use: L[n] 
comm[L[n_], L[m_]] := n - m

 Then you can call the function like this: 
comm[L[15], L[8]]