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?

  • 8
    $\begingroup$ 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/…) $\endgroup$ – Searke Apr 8 '16 at 18:13
  • 1
    $\begingroup$ @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. $\endgroup$ – Searke Apr 8 '16 at 18:38
  • 2
    $\begingroup$ @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. $\endgroup$ – Searke Apr 8 '16 at 18:40
  • 2
    $\begingroup$ 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. $\endgroup$ – andre314 Apr 8 '16 at 18:43
  • 1
    $\begingroup$ @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". $\endgroup$ – Searke Apr 8 '16 at 18:50

Browse other questions tagged or ask your own question.