#Automatically inserting alignment points

9 messages · Page 1 of 1 (latest)

cerulean prairie
#

I am writing some text that has many equations that are left aligned like this:

?r

$
&X &&= a W + a Z \
&W &&= b X \
&Z &&= 1
$
#

Is there a way to get this result without manually adding the alignment points every time?

I tried inserting the alignment points automatically, but nothings seemed to work great. I couldn't figure out how to "split" on the
= signs. The closest I could get was to slice at fixed indices, but that didn't work either because some whitespace node throw off the math.

#let insert_alignments(eqn) = {
    for line in array(eqn.body.children).split(linebreak()) {
        let a = line.slice(0,1).join()
        let b = line.slice(2).join()
        $ &#a && #b $
    }    
}

#insert_alignments($
X = a W + a Z \
W = b X \
Z = 1
$)
onyx tusk
#

can't say I'd recommend it, but you can do something like this.

#

?r

#show math.equation.where(block: true): it => {
  show "=": $&=$
  it
}

$
a = b + 30 \
c + d = e + 40
$
cerulean prairie
#

Clever! Is there a way to also add a "&" at the start of every line?

onyx tusk
#

i guess you could do this

#

?r

#show math.equation.where(block: true): it => {
  if it.body.children.first() == $&$.body {
    // prevent infinite recursion
    return it
  }

  show linebreak: it => $#it&$
  show "=": $&&=$
  $ &it $
}

a

$
a = b + 30333 \
c + d = e + 40
$
b