How to conditionally enable equation numbering for labeled equations?

Slightly shorter variant which also ensures correct numbering in presence of inline equations:

#set math.equation(numbering: "(1)")
#show math.equation: it => {
  if it.block and not it.has("label") [
    #counter(math.equation).update(v => v - 1)
    #math.equation(it.body, block: true, numbering: none)#label("")
  ] else {
    it
  }  
}

Explanation

The set rule enables numbering for all equations.
The show rule handles block equations without label specially by displaying a copy of the equation without numbering. To ensure that these equations are not counted, the counter is decremented. To avoid recursion, an empty label is added.

Example

Full code
#set page(width: 100pt, height: auto)


#set math.equation(numbering: "(1)")
#show math.equation: it => {
  if it.block and not it.has("label") [
    #counter(math.equation).update(v => v - 1)
    #math.equation(it.body, block: true, numbering: none)#label("")
  ] else {
    it
  }  
}


$a$ to the one:
$ a^1 $
$b$ to the two:
$ b^2 $ <b>
$c$ to the three:
$ c^3 $
$d$<x> to the four:
$ d^4 $ <d>

1 Like