Hello everyone!
I have been trying to port a small LaTeX package that I’ve made based on coloredits. It is a package for annotation of documents by multiple authors. One of its features is the dynamic declaration of macros whose names are specified by one initial string (the author’s name). If I add an author named alvaro, the following macros are automatically created: alvaroadd, alvaroremove, alvaroreplace, alvaromark, alvarocomment, and alvaronote. While porting it to Typst, I have found no way to dynamic declare a function like this in order to simulate this behaviour.
This is the Typst code (in a summarized version):
#let default-color = blue
#let authors = state("authors", (:))
#authors.update(("default": (added: default-color, removed: default-color.transparentize(50%), background: default-color.transparentize(90%))))
#let add-author(name, color: default-color) = {
authors.update(old => old + ((name): (added: color, removed: color.transparentize(50%), background: color.transparentize(90%))))
}
#let note(body, author: "default") = {
...
}
#let add(body, obs: none, author: "default") = {
...
}
#let remove(body, obs: none, author: "default") = {
...
}
#let replace(old-body, new-body, obs: none, author: "default") = {
...
}
#let mark(body, obs: none, author: "default") = {
...
}
#let comment(body, author: "default") = {
...
}
This is the current use for the package:
#add-author("alvaro", color: green)
#let alvaroadd = add.with(author: "alvaro")
#let alvaroremove = remove.with(author: "alvaro")
#let alvaroreplace = replace.with(author: "alvaro")
#let alvaromark = mark.with(author: "alvaro")
#let alvarocomment = comment.with(author: "alvaro")
#let alvaronote = note.with(author: "alvaro")
#alvaroadd(obs: [Observation.])[Add test.].
Currently, I have to explicitly declare each of the author’s functions using #let <authorname>add = add.with(author: "authorname") for each author. I would like to ask you if there is a way to automatically declare these functions? This is what I would like to happen:
// Functions "alvaroadd", "alvaroremove", etc. are automatically declared inside "add-author".
#add-author("alvaro", color: green)
#alvaroadd(obs: [Observation.])[Add test.].
Thank you very much. Cheers!
