I think the problem is that rect (and box etc…) mess with math mode. (This is a known issue i think). I don’t really know of a workaround. However, you can probably achieve what you want using mannot – Typst Universe
When you insert a rect, block or box into the equation, and then an equation inside that, then you have a “math boundary” (let’s call it that) where the inner equation has no connection to the outer equation. So it loses its size information (the size context is that the outer equation is a block/display equation).
If you want to draw boxes inside equations, use package mannot:
(in this case using std. and not leaving math mode). I would prefer the first solution because it is easier to work with one equation instead of these nested equations (size, alignment, labels & references, etc).
Hi @andres.gimenez, thank you for your question. Unfortunately it is currently hard to understand. Could you please take the time and incorporate the feedback @nleanba gave you? They gave a good overview about how you could vastly improve your question. Keep in mind, ideally your question can help future visitors facing the same problem. The better you describe your problem, the more useful your question becomes.