I’m trying to create a function to be mark inline actions in a run of text which indicate the assignee in a margin note (via the drafting module) and then add them to a global dictionary to be able to render a table later at the end of the document.
This was my attempt:
// Create a dictionary to store actions for each assignee.
// The key will be the assignee and the value will be array of actions
// Due to scoping constraints, use the "state" function
#let actions = state("actions", ("": ()))
// Define a helper function to add an action to the global dictionary
#let _add_action(assignee, action) = {
let actions_for_assignee = actions.at(assignee, ())
actions_for_assignee.append(action)
actions.update(assignee, actions_for_assignee)
}
// Define an action for use in the body text
#let action(body, assignee: "", side: left) = {
// Add action to the global state to be able to render a table later
_add_action(assignee, body)
// Display the action text inline as usual
body
// Mark the presence of an action in a sidenote with the assignee
margin-note(side: side)[#strong("Action:") #assignee]
}
Here's an example of text with an #action(assignee: "Ben")[action for Ben to do].
This won’t compile, complaining at line
let actions_for_assignee = actions.at(assignee, ())
“text is not locatable”
I suspect I’m misunderstanding how dictionaries and/or state variables should working. Any suggestions would be very welcome!