# How to declare a variable with subscript being numbers? [duplicate]

everyone! I hope to declare a variable with subscript as numbers, for example, $x_{10}$, $x_{11}$, $x_{01}$ as variables. Is it possible in mathematica? If so, how to implement it so that it treats $x_{10}$ as a variable? Thank you!

• Hi ! You should add some details to your question, because it is not clear what you are actually trying to do. Add a simple (non)working example showing your goal, etc. – Sektor Feb 5 '15 at 21:09
• Although you can do something like this it is generally advised not to do this. But have a look at the Notation package if you really want this. – Sjoerd C. de Vries Feb 5 '15 at 21:52
• Is there some reason why the usual Ctrl + _ won't work? – DumpsterDoofus Feb 6 '15 at 1:23

Format[x[i_, j_]] :=
Subscript[x, StringJoin[ToString /@ {i, j}]]

t = Total[{x[1, 0], x[1, 1], x[0, 1]}]


Solve[t == 1, x[0, 1]]


Using the 'Notation' package, you can create real symbols from (not only!) subscripted variables:

Needs["Notation"]

makesymbol[obj_]:=With[{},
If[NameQ@ToString@Unevaluated@obj,Remove@obj]; (* remove possibly existing symbol first *)
Symbolize@ParsedBoxWrapper@ToBoxes@obj;]       (* then create the new symbol *)


With this function, you can create a symbol like so:

makesymbol[Subscript[x,"01"]]


Mathematica will now treat it the same as any other (simpler) symbol.

And the best part is:

1. You have the same look&feel everywhere, both in your code and the generated output.
2. It works for all kinds of notation, not only Subscript`

I hope this might be of some help to you.