Marmare314 / lemmify

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

Feat: Add tags which can be provided on each theorem instantiation an… #22

Open marc-thieme opened 4 months ago

marc-thieme commented 4 months ago

This PR adds a tags field to the numbering attachment of the theorem figures. For each instance of a theorem by the document author, they can provide a list of named tags the want to attach to the theorem. These tags will be available to the styling function through params.tags..
I would still need to add tests and some documentation for discoverability of the feature. But before that, I would like to know if you would be open to merging this feature:

Use case for the feature

When each instance of a theorem in your document needs instance-specific metadata to be styled correctly.
For example, I recently prepared for an exam and compiled a collections of theorems we needed to know. I wanted to annotate my theorems with the exam that they were questioned for. The only way this was really possible was by jumbling them up into the name attribute, which was very limiting.

Note this example using my proposed implementation.

#let custom-styling(thm) = {
  let params = lemmify.get-theorem-parameters(thm)
  let number = (params.numbering)(thm, false)
  params.name
  h(1fr)
  params.kind-name + " " + number
  h(1fr)
  params.tags.exam
  block(params.body, stroke: yellow, inset: 0.8mm)
}
#let (theorem, theorem-rules) = lemmify.default-theorems(style: custom-styling, tags: (exam: "all exams"))
#show: theorem-rules

#theorem(name: "Eulerian tour", exam: "WS19")[
  A graph contains an eulerian tour iff the degree of each vertex is even
]

The code relies on knowing the theorem name and the exam separately, so it can inject the theorem in between them.

Design and considerations

The proposal at hand:

Possible alterations and their downsides:

The implementation at hand is the most conservative one imo

Marmare314 commented 4 months ago

Thanks for the PR! I think allowing custom arguments to be passed to the styling function definitely makes sense (I thought I already added this, but apparently I did not). By that I mean extending create-theorem with an argument sink (probably only allowing named arguments as you suggested) and just passing them along to the styling function. What I'm not so sure about is adding a specific argument like "tags", as to me it looks quite specific to your use-case. But with the above approach this should be reasonably simple to implement.

Also I'm not sure when/if I want to release this refactored version since I'm still not quite happy with how it turned out (see #23), and I want to avoid too many breaking changes. Unfortunately adding this feature to main is probably not possible.