How can I instantiate a dictionary with a variable key name?

You’re looking for this syntax:

#let userName = "joe"
#let userData = (birthday: 1, phone: 123)

#let dict1 = ((userName): userData)
#dict1

This is not really special syntax, it’s just a parenthesized expression. As you’ve seen, a bare identifier will be directly used as the key – but any other expression will be evaluated to get the key. By putting the identifier in parentheses, you make sure that a variable access is performed.

3 Likes