This is indeed a surprisingly non-trivial problem, as the interaction between math content and regular content isn’t optimal right now. However, there is a very useful package called mannot, which allows the kind of boxing you’re looking for (and much more):
#import "@preview/mannot:0.2.2": markrect
$ integral_0^(+oo) e^(-x^2) dif x = markrect(sqrt(pi)/2) $