#show math.equation: set text(font: "Fira Math")
// Using quotes -> upright Fira Math
$"Upright text" x + y = z$
// Using function `math.op` -> upright Fira Math with slightly less spacing
$op("Upright text") x + y = z$
// Using function `math.upright` -> upright Fira Math
$upright("Upright text") x + y = z$
// Using function `text` -> upright Fira Math
$text("Upright text") x + y = z$
// Using function `text` with own font -> own upright font
$text(font: "Libertinus Serif", "Upright text") x + y = z$
So you would want to use the last option, where Libertinus Serif is known to be the default outside font:
#let fun(arg) = $text(font: "Libertinus Serif", arg)_n$
// In code, use as any of the following
$fun("xyz") 1 + 1 = 2$
$#fun[xyz] 1 + 1 = 2$
$#fun([xyz]) 1 + 1 = 2$
Further automation might be possible throught context. That way, the outside font would be automatically applied.
In principle it’s impossible, because the function itself can’t change the type of argument produced on the side calling the function. In general, when a function is called in math mode, the argument will be some kind of content, as demonstrated: