How do I use #case while maintaining & alignment?

I have the following LP problem formulation:

$
  min quad &9x_1 + 12x_2 + 10x_3 + 12x_4 + y_1 + y_2 + y_3 + y_4 \
  s.t. quad &x_1 - 100 = y_1 \
            &y_1 + x_2 - 150 = y_2 \
            &y_2 + x_3 - 200 = y_3 \
            &y_3 + x_4 - 170 = y_4 \
            & x_1 gt.eq 100 \
            &y_1 + x_2 gt.eq 150 \
            &y_2 + x_3 gt.eq 200 \
            &y_3 + x_4 gt.eq 170 \
            &x_t, y_t gt.eq 0 quad forall t = 1, dots, 4 
$

I’d like to maintain the alignment as it currently stands while adding the #case as shown below:

#import "@preview/mannot:0.3.0": *
#import "@preview/cetz:0.3.4"

#let annotate-brace(start, end, body) = {
  cetz.decorations.brace(start, end, name: "a", stroke: green)
  cetz.draw.content("a.east", anchor: "west", padding: 0.2, text(green, body))
}

#let offset-brace-start-end(start, end) = (
  (rel: (0.5, +0.5em), to: (start, "-|", end)),
  (rel: (0.5, -0.5em), to: end),
)

$
   min quad & 9x_1 + 12x_2 + 10x_3 + 12x_4 + y_1 + y_2 + y_3 + y_4 \
  s.t. quad & x_1 - 100 = mark(y_1, tag: #<y1>)                    \
            & y_1 + x_2 - 150 = y_2                                \
            & y_2 + x_3 - 200 = y_3                                \
            & y_3 + x_4 - 170 = mark(y_4, tag: #<y4>)              \
            & x_1 >= mark(100, tag: #<100>)                        \
            & y_1 + x_2 >= 150                                     \
            & y_2 + x_3 >= 200                                     \
            & y_3 + x_4 >= mark(170, tag: #<170>)                  \
            & x_t, y_t >= 0 quad forall t = 1, dots, 4             \
  #annot-cetz((<y1>, <y4>, <100>, <170>), cetz, {
    annotate-brace(..offset-brace-start-end("y1", "y4"))[I.B.]
    annotate-brace(..offset-brace-start-end("100", "170"))[D.F.]
  })
$

Or slightly more compact:

#import "@preview/mannot:0.3.0": *
#import "@preview/cetz:0.3.4"

#let annotate-brace(start, end, body) = {
  cetz.decorations.brace(start, end, name: "a", stroke: green)
  cetz.draw.content("a.east", anchor: "west", padding: 0.2, text(green, body))
}

#let offset-brace-start-end(start, end) = (
  (rel: (0.5, +0.5em), to: (start, "-|", end)),
  (rel: (0.5, -0.5em), to: end),
)

#let tag(body, tag) = mark(body, tag: label(tag))

$
   min quad & 9x_1 + 12x_2 + 10x_3 + 12x_4 + y_1 + y_2 + y_3 + y_4 \
  s.t. quad & x_1 - 100 = tag(y_1, "y1")                           \
            & y_1 + x_2 - 150 = y_2                                \
            & y_2 + x_3 - 200 = y_3                                \
            & y_3 + x_4 - 170 = tag(y_4, "y4")                     \
            & x_1 >= tag(100, "100")                               \
            & y_1 + x_2 >= 150                                     \
            & y_2 + x_3 >= 200                                     \
            & y_3 + x_4 >= tag(170, "170")                         \
            & x_t, y_t >= 0 quad forall t = 1, dots, 4             \
  #annot-cetz((<y1>, <y4>, <100>, <170>), cetz, {
    annotate-brace(..offset-brace-start-end("y1", "y4"))[I.B.]
    annotate-brace(..offset-brace-start-end("100", "170"))[D.F.]
  })
$

image

Cc @ryuryu

1 Like

Wow thank you. I would have never come up with this on my own :joy:

1 Like