How to properly align math?

I have this:

$
    min -2 & x_1 -3  &       x_2 \
       "u.d.N." & x_1 + 2 &  x_2 <= 8 \
         2 & x_1 +   &  x_2 <= 9 \
           &         & -x_1 <= 0 \
           &         & -x_2 <= 0 \
           &         & x in ZZ^2
$

I would expect this to align all the x_1s and x_2s, but the first one isnโ€™t being aligned correctly

Will this satisfy you?

$
         min -2 x_1 & - & 3 x_2 & #hide($=$) \
  "u.d.N." quad x_1 & + & 2 x_2 & <= 8 \
              2 x_1 & + &   x_2 & <= 9 \
                    & - &   x_1 & <= 0 \
                    & - &   x_2 & <= 0 \
                    &   &     x & in ZZ^2
$

Or maybe this?

$
         min -2 x_1 && - 3 x_2 & #hide($=$) \
  "u.d.N." quad x_1 && + 2 x_2 & <= 8 \
              2 x_1 &&   + x_2 & <= 9 \
                    &&   - x_1 & <= 0 \
                    &&   - x_2 & <= 0 \
                    &&       x & in ZZ^2
$

Explanation

Quoting Math โ€“ Typst Documentation

When equations include multiple alignment points (&), this creates blocks of alternatingly right- and left-aligned columns. โ€ฆ Each alignment point (&) simply alternates between right-aligned/left-aligned.

In addition, I have to use the hide function to fix a small deviation, which might be a typst bug?

Without hide:

1 Like

IMO, this is better:

#let hide = hide
#let blq = $hide(=)$ // blank equal

$
  & min      & -2 x_1 & - & 3 x_2 & blq \
  & "u.d.N." &    x_1 & + & 2 x_2 & <= 8 \
  &          &  2 x_1 & + &   x_2 & <= 9 \
  &          &        & - &   x_1 & <= 0 \
  &          &        & - &   x_2 & <= 0 \
  &          &        &   &     x & in ZZ^2
$

The only thing I wonder if the hidden content is also excluded for AT.