How to break a long equation into multiple lines without numbering each row

I suggest the following solution. I suggested an updated version of multiline in the other thread. And equate can be used to number each line of an equation - so that should have both necessary variants covered.

#import "@preview/equate:0.3.2" 
#import "@preview/physica:0.9.7": pdv
#let number-every = equate.equate
#set math.equation(numbering: "(1)")

#show: block.with(width: 10cm, stroke: 1pt, outset: 0.25em)
#let vv = x => math.bold(math.upright(x))

*align*: Regular equations in Typst support alignment points. We use `equate` to support numbering and labelling each line of an equation separately.
#number-every[$
  nabla dot vv(E) &= rho / epsilon_0 #<gauss> \
  nabla dot vv(B) &= 0 \
  nabla times vv(E) &= - pdv(vv(B), t) \
  nabla times vv(B) &= mu_0 vv(J) + 1/c^2 pdv(vv(E), t)
$]

@gauss is known as Gauss's law.

#let add-label(elt, label) = [#elt#label]
/// Create a multiline equation
/// Note: this function is semi-incompatible with equate!
/// (equate doesn't allow the equation to have numbering - you need to label it with equate:revoke to work around this, which removes the ability to put other labels on the equation.)
#let multiline(eq, numbering-pad: 2em, spacing: 0.65em) = {
  if eq.body.func() != [].func() { return eq }
  let label = eq.at("label", default: none)  // preserve the original label
  let parts = eq.body.children.split(linebreak())
  let inner(body, alignment) = {
    set block(spacing: spacing)
    show math.equation: set align(alignment)
    add-label(math.equation(body, block: true, numbering: none), <equate:revoke>)
  }
  if parts.len() <= 1 { return eq }
  let (a, ..middle, c) = parts.map(array.join)
  add-label($
    #block(width: 100%, inset: (right: numbering-pad), {
      inner(a, left)
      middle.map(eq => inner(eq, center)).join()
      inner(c, right)
    })
  $, label)
}


*multiline*: We use a custom function to create something like a multiline equation for Typst. The first line is left align, the middle lines center aligned, and the last one is right aligned.
#multiline[$
  a + b + c + d + e + f \
  + med i + j + k + l + m + n \
  + med x + y + z + integral f(x) dif x
$<my-eq>]

My @my-eq is multiline.
1 Like