-
-
Notifications
You must be signed in to change notification settings - Fork 59
Description
#331 highlights an issue in the way we currently deal with variable and function names when it comes to subscripting. Substituting in strings leads to some strange edge cases, and the code is pretty difficult to parse.
I suggest a new model: any symbol (that could represent a variable name or a function name) is only normalized once. It follows something like this schedule:
- Unicode substitution (
:a₁ --> :a_1) - The string is split into "sub-symbols" (
:abc_x_y --> (:abc, :x, :y)) - Each sub-symbol is normalized separately
- If
snakecase, sub-symbols arejoined with\_, otherwise all but the first pair are ("abc_{x\_y}")
Sub-symbol normalization:
- If matches constant list (e.g.
inf,atan), get normalized form from dict - If more than one (alphabetical) character,
\mathrm(configurable?) - Else return sub-symbol as is
This leaves an uncertainty in how to sort indexing (a_1[3]), and breaks the current behavior of latexify(:abc) --> "$abc$". It will however be more consistent with mathematical notation.
The indexing uncertainty is the biggest block to me, we might have to consider using a placeholder struct, more or less saving :a_b as a special type of :a[:b] and delaying the stringification, but that will require a bit of an overhaul.