# Syntax question for declaring variables [duplicate]

I have a very basic syntax question for declaring $X_{hb}$ a variable.

f[Subscript[X, hb_]] := Subscript[X, hb]


In mathematica instead of writing the Subscript[] code, I simply use the ctrl+_ shortcut to place whatever I want in the subscript. However, after doing this I do not know how make mathematica consider $X_{hb}$ as a variable since placing the _ after it is considered to be an unrealted character.

See here: http://i.imgur.com/XWZHssm.png

How do I fix this issue?

• 1. Don't use Subscripts. 2. If you won't listen to rule 1, then see this answer to your question (mathematica.stackexchange.com/questions/1004/…) (mathematica.stackexchange.com/questions/13741/…) – Searke Apr 8 '16 at 18:13
• @Ozera There is a logic behind how Subscripts work in Mathematica. Since subscripts are vague and often interpreted in contradictory ways, Mathematica treats them like generic expressions and requires that you tell it what they mean. Most people don't realize how vague and contradictory their different uses of subscripts tend to be. – Searke Apr 8 '16 at 18:38
• @Ozera You can use greek letters as variables just fine in Mathematica. It's just terrible form to program with undescriptive variable names. Write descriptive variable names. Write "variance" instead of using a sigma. This is a rule to follow in practically any programming language, not just Mathematica. – Searke Apr 8 '16 at 18:40
• I think Greek letters are not a problem in mathematica itself (but is a problem with stack exchange). Instead Subscripts are really a problem. The warning about subscripts is therefore a very good advice. – andre314 Apr 8 '16 at 18:43
• @andre undescriptive variable names are one of the worst parts of debugging other people's Mathematica code. In no other language do people so often use single letter variable names. My worst experience was a notebook where someone has used "t", "tau", a gothic version of "t", and an ancient aramaic character that looks like "t" just because he wanted several different variables that all looked liked "t". – Searke Apr 8 '16 at 18:50