Marmare314 / lemmify

A library for typesetting mathematical theorems in typst.
GNU General Public License v3.0
11 stars 7 forks source link

Referencing is using "link" instead of "ref" #20

Open gdahia opened 6 months ago

gdahia commented 6 months ago

Thanks for the great lib! I am using it a lot for my personal notes and for writing preliminary versions of papers.

That said, I was trying to customize the styling of a template, and realized that referencing for theorems is using the link function instead of the ref function with a custom kind. This makes these references follow the link show rules instead of the ref ones, and so in template customization either we get links with this custom style, or theorem references that do not match the style of the normal text.

I think I figured it out how to do this without changing lemmify by customizing the ref-styling configuration, but I think this changing this inside the core lib might be useful to others. What do you think?

Marmare314 commented 4 months ago

Hi, thank you! It should be using the ref function:

#import "@preview/lemmify:0.1.5": default-theorems

#let (theorem, rules: thm-rules) = default-theorems("thm-group")
#show: thm-rules

#show ref: text.with(red)
#theorem[Test] <thm>
@thm

and so in template customization either we get links with this custom style, or theorem references that do not match the style of the normal text.

I'm not sure what you mean, can you give an example?

gdahia commented 4 months ago

I'm not sure what you mean, can you give an example?

Sure! The following renders "Section 1" in red, but "Theorem 1" in blue:

#import "@preview/lemmify:0.1.5": default-theorems

#let (theorem, rules: thm-rules) = default-theorems("thm-group")
#show: thm-rules

#show ref: text.with(red)
#show link: text.with(blue)
= Introduction
<introduction>
#theorem[Test] <thm>
@thm
@introduction
Marmare314 commented 4 months ago

Ok so I looked into it and unfortunately I don't think there is much that can be done about this. The problem is that the ref function only accepts a target (ie a label) and a supplement and then basically just displays supplement + counter(label).display() and links this to the target. The problem however is that this package allows custom numberings based on the headings counter, which makes it impossible to use the ref function. So the only solution (I could come up with) is to use link instead, which results in this behaviour.

gdahia commented 4 months ago

Perhaps we should take this issue to the maintainers of typst, then? Do you think that there is a good reason for the different behavior in ref and link?