Accessing text.lang requires context. The following three set-if rules have conditions depending on it.
The first one is a bare set-if rule.
The second one is composed into a show-set rule.
The third one is wrapped into the function of a show rule.
// ❌: Can only be used when context is known
#set text(font: "Libertinus Sans") if text.lang == "en"
// ❌: Can only be used when context is known
#show "Why": set text(font: "Libertinus Sans") if text.lang == "en"
// ✅
#show "Why": it => {
set text(font: "Libertinus Sans") if text.lang == "en"
it
}
Surprisingly, the third one compiles but the first two do not. Why?
Aside from explicit context expressions, context is also established implicitly in some places that are also aware of their location in the document: Show rules provide context1 and numberings in the outline, for instance, also provide the proper context to resolve counters.
1: Currently, all show rules provide styling context, but only show rules on locatable elements provide a location context
Here’s one way to provide the context, by wrapping the rest of the document in a context block:
#show: doc => context {
set text(font: "Libertinus Sans") if text.lang == "en"
show "Why": set text(font: "Libertinus Sans") if text.lang == "en"
doc
}
This could also be used inside a template function, for example.