Marmare314 / lemmify

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

Why is the styling only applied through the show rule instead instead of directly? #21

Open marc-thieme opened 4 months ago

marc-thieme commented 4 months ago

https://github.com/Marmare314/lemmify/blob/599c805f51dec6758f86ca4d16fc9edf9dc2a06c/src/theorem.typ#L34

I tried to get familiar with the codebase just now (your refactor helped a lot, it's amazing!) and I got a bit confused by the show rules everywhere (was worse before the refactor).

Therefore, I was wondering why you use show rules even for the styling of the theorems themselves. Of course, the rules for ref and link must be applied by the top-level scope, but why do you also add the styling only with the show-rule as well, instead of applying it ad-hoc when creating the theorem?

I added the codeline where you attach the styling function to the numbering so you can retreive it later in the show-rule. Couldn't you avoid this by passing the styling along to the figure constructor?

marc-thieme commented 4 months ago

Also, wouldn't an advantage of this approach be to decouple the semantic definition and counter etc. from the styling of the element? Why not dismiss the styling parameter entirely and let it upon the user to apply a styling using show rules.

Marmare314 commented 4 months ago

Therefore, I was wondering why you use show rules even for the styling of the theorems themselves.

If you set the caption attribute of a figure it will be displayed by default.

#figure(
  kind: "SomeKind",
  supplement: "SomeSupp",
  block([Hello], width: 100%, fill: gray, inset: 1em),
  caption: "SomeCaption"
)

So what you need to add is #show figure.where(kind: "SomeKind"): fig => fig.body. Since some rule has to be applied for the styling anyway I decided to just apply everything there. There might also be some subtle problem with the way the theorem numbering works, but I think it should be fine. In principle there is (probably) nothing against doing that and it would maybe make the logic a bit easier to follow.

Couldn't you avoid this by passing the styling along to the figure constructor?

Do you mean "passing the styling along to the figure constructor" as in replacing body with style(body)? In that case probably (as long as there is no problem with the numbering implementation as above).

Also, wouldn't an advantage of this approach be to decouple the semantic definition and counter etc. from the styling of the element?

I don't think so since the numbering still needs to be inserted in the styling.

Why not dismiss the styling parameter entirely and let it upon the user to apply a styling using show rules.

That should work. I probably didn't consider this because it did not work before the refactor. But default-theorems should probably still accept a style to keep it easier to use.