Suppose I have custom equation numbering & referencing as follows.
#set math.equation(numbering: it => numbering("(1.1)", counter(heading).get().at(0), it))
#set heading(numbering: "1.1")
#show heading.where(level: 1): it => {
counter(math.equation).update(0)
it
}
#show ref: it => {
let el = it.element
if (el != none and el.func() == math.equation) {
let loc = el.location()
return link(loc,numbering(
el.numbering,
..counter(math.equation).at(loc)
))
}
return it
}
=
$ a^2 + b^2 = c^2 $ <eq>
=
$ a^2 + b^2 = c^2 $
Now look at this reference: @eq.
It should say (1.1) but it says (2.1)
Notice that the equation referencing is wrong.
How would one go about fixing this?
I think the following solution is quite nice: Wrong numbering for the equation - #2 by Eric. Basically you don’t change the ref, but just reset the equation counter after each heading.
From what I can tell, the goal of the show rule on ref is to change the appearance of a reference from Equation 2.1 to just (2.1). The unfortunate thing is that you have to explicitly call numbering(..) in the show rule, so the numbering function set in the rule for equations is always called with the context of the reference (instead of the context of the equation itself). The only possible workaround I could think of right now, is using a regex show rule to remove the supplement like this:
#show ref: it => {
let el = it.element
if (el != none and el.func() == math.equation) {
// May need to adjust this when using letters in numbering
show regex("\p{letter}+\s+"): none
it
} else {
it
}
}
Other than that, there are some potentially related issues you could follow: