EpicEricEE / typst-equate

A Typst package for various enhancements for mathematical expressions.
MIT License
12 stars 1 forks source link

`numbering` function does not get local counter for sub-equations #3

Open hbierlee opened 2 months ago

hbierlee commented 2 months ago

Hi,

Great package!

I'm running into a specific issue where the numbering function does not get local counter for sub-equations, like it does for regular equations (which allows the user to create a CHAPTER.EQUATION_NUMBER type numbering).

I am trying to achieve a CHAPTER.EQUATION_NUMBER.SUB_EQUATION_NUMBER, but:


#import "@preview/equate:0.2.1": equate
#set heading(numbering: "1.1")
#show: equate.with(breakable: true, sub-numbering: true)
#set math.equation(
  numbering: (..nums) => numbering("(1.1)", counter(heading).get().first(), ..nums),
)

= Chp 1

= Chp 2

$
  1+1=2 #<eq:1:1>\
  1+2=3
$ <eq:1>

= Chp 3

- The ref to equation @eq:1 gets the local counter
- But a ref to a sub-equation does not: @eq:1:1 $!=$ (2.1.1), instead gets counter
  to _current_ chapter 3.

Link: playground

image

Cheers,

Henk

EpicEricEE commented 2 months ago

I think there currently isn't a way for me to apply the numbering in the context of the referenced equation, as this would require something like typst/typst#3930.

hbierlee commented 2 months ago

Thanks for the quick reply. I see, I already thought it was a bit magic that this works for equations in the first place. Feel free to close this issue or to leave open to wait for the required typst feature to get implemented.

hbierlee commented 1 month ago

For those interested, I think I've found a workaround to still get CHAPTER.EQUATION_NUMBER.SUB_EQUATION_NUMBER (which I really like as referencing style).

I just reset the numbering argument of math.equation at the start of each chapter:

= Chp 2
#set math.equation(
  numbering: (..nums) => numbering("(1.1)", 2, ..nums), // hard-code chapter 2 as the first number
)

If you add your chapters dynamically, you can further automate this. (Or maybe this could be added as part of a show rule for heading, but I haven't tried this.).