Thanks for the answer and pointing me towards relevants discussions. Sorry I did not find them before asking.
I found pretty much what I wanted at What is the best way to retrieve template argument outside the template? - #3 by PgBiel . Basically, the trick is to have a setup function in which I initialize the dictionnary color_lib and update it based on the theme input param. The function also spits out a template function, and both are given the user.
I don’t know how standard this trick is, but the question seems to have surfaced many times in pretty much the same way. Maybe it could be added to the (overwise very helpful) tutorial Making a Template – Typst Documentation .