Skip to content

Commit

Permalink
Feat: Add tags which can be provided on each theorem instantiation an…
Browse files Browse the repository at this point in the history
…d which are accessible to the styling
  • Loading branch information
marc-thieme committed Feb 23, 2024
1 parent 599c805 commit 118a429
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
#let LEMMIFY-DEFAULT-THEOREM-GROUP = "LEMMIFY-DEFAULT-THEOREM-GROUP"
#let LEMMIFY-DEFAULT-PROOF-GROUP = "LEMMIFY-DEFAULT-PROOF-GROUP"

#let validate-and-extract-tags(tag-defaults, tags-args) = {
assert-type(tags-args, "tags", arguments)
assert(tags-args.pos() == (), message: "The tags (custom parameters) may not be positional. Yours were " + repr(tags-args.pos()))
let tags = tag-defaults

for (key, value) in tags-args.named() {
assert(key in tag-defaults, message: "Your tag with the key " + key + "(=" + repr(value) + ") was not expected")
tags.insert(key, value)
}

return tags
}


/// Creates a new #ref-type("theorem-function").
///
/// - kind-name (str): The name of the theorem kind. It also acts
Expand All @@ -24,26 +38,33 @@
/// which is then used in the #ref-type("theorem-numbering-function").
/// - style (style-function): Specifies how the #ref-type("theorem")s will look. This will only be
/// visible once the @@theorem-rules() have been applied.
/// - tags (dictionary): Tags are optional parameters the author can previde for each instance of a
/// theorem in his document separately. A dictionary whose keys are the available tags for this
/// kind of theorem and the values are the default values for those tags.
/// Tags are exposed to the styling function through the 'tags'-value of the theorem parameters.
/// -> theorem-function
#let theorem-kind(
kind-name,
group: LEMMIFY-DEFAULT-THEOREM-GROUP,
link-to: last-heading,
numbering: numbering-concat,
subnumbering: "1",
style: style-simple
style: style-simple,
tags: (:)
) = {
assert-type(kind-name, "kind-name", str)
assert-type(group, "group", str)
assert-type(link-to, "link-to", label, selector, function, None)
assert-type(numbering, "numbering", function, None)
assert-type(subnumbering, "subnumbering", function, str, None)
assert-type(style, "style", function)
assert-type(tags, "tag defaults", dictionary)

return (
name: none,
link-to: link-to,
numbering: numbering,
..provided-tags,
body
) => create-theorem(
name,
Expand All @@ -53,6 +74,7 @@
numbering,
subnumbering,
style,
validate-and-extract-tags(tags, provided-tags),
body
)
}
Expand Down Expand Up @@ -110,6 +132,7 @@
/// be reset on headings below `max-reset-level`.
/// And if `link-to` is set to `last-heading`
/// higher levels will not be displayed in the numbering.
/// - tags (dictionary):
/// -> dictionary
#let default-theorems(
group: LEMMIFY-DEFAULT-THEOREM-GROUP,
Expand All @@ -122,7 +145,8 @@
link-to: last-heading,
proof-link-to: none,
subnumbering: "1",
max-reset-level: none
max-reset-level: none,
tags: (:),
) = {
assert-type(group, "group", str)
assert-type(proof-group, "proof-group", str)
Expand Down Expand Up @@ -150,7 +174,8 @@
numbering: numbering,
subnumbering: subnumbering,
style: style,
link-to: link-to
link-to: link-to,
tags: tags,
))
}

Expand All @@ -160,7 +185,8 @@
numbering: proof-numbering,
subnumbering: subnumbering,
style: proof-style,
link-to: proof-link-to
link-to: proof-link-to,
tags: tags,
))

let rules = concat-fold((
Expand Down
2 changes: 2 additions & 0 deletions src/theorem.typ
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
numbering,
subnumbering,
style,
tags,
body
) = {
assert-type(name, "name", str, content, None)
Expand All @@ -31,6 +32,7 @@
link-to: link-to,
numbering: numbering,
subnumbering: subnumbering,
tags: tags,
style: style
)
)
Expand Down

0 comments on commit 118a429

Please sign in to comment.