Convert superscripts to MathJax
Husk, 43 41 40 bytes
`JD;&quot;¦$&quot;ṁ?Iȯ:'^`J&quot;{}&quot;ṁos€&quot;¹²³⁴⁵⁶⁷⁸⁹&quot;Λ√ġ√

Try it online!
The superscripts are 1 byte each since they're in Husk's codepage.
I wanted to replace +₁+₁ with S+`+&quot;¦$&quot; but it didn't work for some reason.. :(
-2 bytes borrowing the indexing idea from hyper-neutrino.
-1 byte from Leo.
Explanation
`JD;&quot;¦$&quot;ṁ?Iȯ`:'}+&quot;^{&quot;ṁos€&quot;¹..⁹&quot;Λ√ġ√
                              ġ√ group on alphabets
     ṁ                           map and concatenate with:
      ?                            if:
                            Λ√      the group is alphabetical
       I                             leave as is
        ȯ`:'}+&quot;^{&quot;ṁos€&quot;¹..⁹&quot;        otherwise:
                  ṁȯ                  map and concat each char to:
                     €&quot;¹..⁹&quot;           index in ¹..⁹(0 if not present)
                    s                  cast to string
             +&quot;^{&quot;                    prepend &quot;^{&quot;
         `:'}                         append '{'
`JD;&quot;¦$&quot;                            surround the final string with &quot;\$&quot;