I wasn’t very clear, but just imagine that you have a fairly large number of variables, each being used in different ways with sub- and supscripts.
If for some reason you are in the situation where you wish to change your “mathematical symbol”, e.g., from xi to zeta, then you have to do a search and replace in the editor.
In equations, symbols are all exported by default so you don’t have to prefix it with the module, but a symbol is only that, a symbol.
If you consider a mathematical variable to be a programming variable instead, then you might get some useful features, such as renaming, i.e., changing what the variable corresponds to.
Obviously, the problem isn’t trivial, because you are dealing with a good number of steps. That is, you start with
#let xi = math.xi
$xi$ // here, xi is #xi replaced by sym.xi
$#xi$ // #xi is the variable xi
In the case above, the variable xi
supersedes sym.xi
. If you want to change xi
to math.zeta
, then you change the variable assignment to math.zeta
.
#let xi = math.zeta
$xi$ // sym.xi
$#xi$ // math.zeta
In that situation, you still end up with a confusing notation, where xi:=zeta
instead. Preferably, then you would rename the variable xi to zeta
.
#let zeta = math.zeta
$xi$ // sym.xi
$#zeta$ // math.zeta
There you go! you modified the xi
math. var. to zeta
, but then any xi
who didn’t correctly call zeta
is “forgotten” and has to be fixed up manually.
The obvious follow-up question is: why would you assign a variable in the first place, why don’t you just search and replace?
I often end up encountering symbol conflicts in my equations, where I already used a letter in a different context, or with a different subscript. Ideally, if everything is linear and you do not use the previous meaning after a certain point, then you can just re-use the same variable. If both meaning are used at the same time, then you’re in trouble!
#let k = $k$ // k param
$k=1,...,K$ // k is an index
$i=1,...,N-k$ // k is a parameter
you could get in trouble very quickly if you search & replace too quickly or modify your variable without anticipating symbol conflict.
Best practice here is to obviously not re-use the same symbol for different meanings, but sometimes you’re just out of letters
.
If you scope the meaning using variable assignments, then you are able to map 1-to-1 a meaning to a symbol. You also get renaming variables, changing the content, etc. out of the box.
#let kindex = $k$
#let kparam = $k$
$kindex=1,...,K$ // index k
$i=1,...,N-kparam // variable k
but frankly, this syntax is ugly! I wish there an easier way to map “meaning” to “symbol” and still get precious QoL features. You could abbreviate even further with ki
and kp
, but then its harder to know what is what. Using a dictionary is similar, but even worse because dictionary.get
is not “inlined” in equations, so you have to add #k.index
, and it’s still ugly.
I have no idea what the “ideal” syntax would look like, but it is probably not using programming variables as it reduces the advantage of using Typst in the first place (for me at least), which was to have a human-friendly equation syntax, similar to troff or lout.