If your use case for a smash function is limited to subscripts and superscripts in math, you can define a function like this
#let smash(body, side: center) = math.display(
box(width: 0pt, align(
side.inv(),
box(width: float.inf * 1pt, $ script(body) $))
)
)
To add some notes about why I did it exactly like this:
- The zero-width box is the main component responsible for the smashing, as it prevents the body from expanding to the side.
- The inner box with infinite width is required so that the body isn’t split into multiple lines.
- The alignment is optional in case you want all the different behaviors you can get in LaTeX with
\mathclap,\mathrlapand\mathllap. - The
displayandscriptfunctions are necessary for keeping the font style and size of the subscript or superscript content, as that information would otherwise be lost as soon as aboxis introduced. - The
script(body)has to be in a block equation so that the bounds of the content are calculated correctly, which is necessary for proper positioning.
You can then use this as in
$ g(t) dot limits(integral)_smash(a+b+c+d)^smash(x+y+z) f(t) dif t $
