How to replace string to superscript?

Hi there!

What I would like to do is to replace parts of a string with their superscript version, for example Dr.in should become Dr.#super[in].

I made it work to replace the “.in” with uppercase, but failed to make it superscript:

#let name = "Dr.in"
#name.replace(".in", m => upper(m.text))
#name.replace(".in", m => super[m])

While upper() seems to be a simple function, taking and returning string, the definition of super() looks quite different. And replace() seems to take one of the functions well, the other one not so much.

Any idea what I am doing wrong?

replace will not work here because it can only produce strings, but what you want is a content (since it’s formatted).

Instead, a scoped show rule will do the job:

#let name = "Dr.in"
#[
  #show ".in": super
  #name
]
1 Like