I am trying to creat a list of indexed variables (symbols) using the Notation package and Symbolize command.

As an example, suppose that I want to a creat a list of variables like ${x_1,...,x_{20}}$ but I want all of them to be symbols. How can I creat a list of symbolized indexed variables?

  • $\begingroup$ Perhaps you could clarify which part you find unexpected, so we can provide better answers. Perhaps we could start from here: Information (i.e. ??) is HoldAll so it won't evaluate Var[[1]] to its contents. You could try Information[Evaluate[Var[[1]]] instead. More in general, however, when you assign values to subscripted variables, the value is actually associated with the Subscript function, and not with the variable. $\endgroup$ – MarcoB Jan 23 '17 at 16:30
  • $\begingroup$ See perhaps (1005), (373). $\endgroup$ – MarcoB Jan 23 '17 at 16:33
  • $\begingroup$ @MarcoB: Ah! So my first question is answered!? :) What about the second one. :) $\endgroup$ – H. R. Jan 23 '17 at 16:33
  • $\begingroup$ @MarcoB: Please note that if one uses the Symbolize command then there will be no problem for assigning. :) $\endgroup$ – H. R. Jan 23 '17 at 16:35
  • $\begingroup$ I am not familiar enough with the Notation package to comment on those points. In general, though, I would suggest that you look into Indexed, or simply use e.g. x[1, 3] instead of $x_{1,3}$. See e.g. (114632) and links, and search this site for "alternatives to Subscript". $\endgroup$ – MarcoB Jan 23 '17 at 16:39

Perhaps you don't need to - you can use a pattern (e.g Subscript[x,_]) inside a Symbolize box. This will generate the symbols as required.

  • $\begingroup$ (+1) Thanks for the attention. :) Yes this would also work. $\endgroup$ – H. R. Mar 8 '17 at 20:33
  • 1
    $\begingroup$ @H.R. if you're indexing by ints greater than 0 note that the pattern that is most protective is _Integer?Positive. $\endgroup$ – b3m2a1 Mar 8 '17 at 23:29
  • $\begingroup$ @MB1965: That is a nice point. It will be good if you add some nice patterns for different indexing to your answer too. :) $\endgroup$ – H. R. Mar 9 '17 at 7:49

Here is as simple way to create a list of symbolized variables $x_1,x_2,\dots,x_{20}$ as follows



Do[Symbolize[ParsedBoxWrapper[SubscriptBox["x", ToString[i]]]], {i, 1,

x = 1

Subscript[x, 1]
  • $\begingroup$ It's worth keeping in mind that this is just front-end magic. If you used GeneralUtilities`PrintDefinitionsLocal on Symbolize you find it just constructs a bunch of symbols looking like x\[UnderBracket]Subscript\[UnderBracket]i and then coerces the box representations with MakeExpression and MakeBoxes. It'll work for most simple usages, but it absolutely requires the front end and the Symbolize call to work. Another point of interest: if you want to get the information on such symbols all one needs to use is ?? "x\[UnderBracket]Subscript\[UnderBracket]*". $\endgroup$ – b3m2a1 Mar 8 '17 at 20:20
  • $\begingroup$ @MB1965: Thanks for the attention. What we see is clearly the front end notation so I find it useful to make use of these things for better readability of the code. :) Also getting information is not that much painful as you say. The keyboard entry is simply "? x crtl+_ 1". :) $\endgroup$ – H. R. Mar 8 '17 at 20:31
  • $\begingroup$ yes, but if you want the definitions for all of the subscripted symbols you require that (I believe). Information takes a placeholder form with "*" to spit out all matching forms but this has to be a string. Similarly with Clear or Remove. $\endgroup$ – b3m2a1 Mar 8 '17 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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