How to apply a transformation to specific variables in math mode?

Is there a way to batch define variables or transform all variable names with a specific suffix in Typst math mode? For example, converting arm, brm, and crm to "a", "b", and "c", and changing acal, bcal to cal(a), cal(b), respectively.

As far as I know typst does not allow you to automatically generate variables. You can however create a script that generates a file with all the variable declarations you need.

Another alternative is to use show rules on strings:

#show math.equation: it => {
  show regex("[a-aAZ]cal"): reg => math.cal(reg.text.first())
  it
}

$
"acal"
$

Hello. What you are describing is not how you should use Typst. It has simple enough math syntax that there is no reason to reinvent the wheel when you can just write $"a" "b" "c" cal(a) cal(b) cal(c)$. You should abstract repetitive complex constructs like left subscript with a shorthand:

#let nC = $attach(C, tl: n)$

$nC_1 nC_2$

Because otherwise the expression will be unreadable:

$attach(C, tl: n)_1 attach(C, tl: n)_2$