How to conditionally enable equation numbering for labeled equations?

And here is another solution without the help of a equ function. Put the following code before your document’s main body.

#show: body => {
  for elem in body.children {
    if elem.func() == math.equation and elem.block {
      let numbering = if "label" in elem.fields().keys() { "(1)" } else { none }
      set math.equation(numbering: numbering)
      elem
    } else {
      elem
    }
  }
}

And you can also append some other settings like this comment.

In this case, the following script

#lorem(30)
$ y = a x + b $ <eq:eq2>
#lorem(19)
@eq:eq2 #lorem(20)
$ E = m c^2 $
#lorem(10)

will result in

image

3 Likes