Repository navigation
Description
Description
A blank line between two set text(lang: ..) rules changes the language the PDF declares, though the page is the same.
#set text(lang: "de")
#set text(lang: "en")
"Hallo"declares en. With a blank line between the two rules, it declares de, though every word is still set in English: the quotes are “Hallo”, where German's are „Hallo“.
It turns up when a document sets its language at its start, as the accessibility guide says to, and then applies a template that sets one too:
#let template(body) = { set text(lang: "en"); body }
#set text(lang: "de")
#show: template
"Hallo"declares en, and de with a blank line before #show.
Compiled, as adjacent.typ and template.typ, and apart.typ and template-apart.typ with the blank line:
for f in adjacent apart template template-apart; do
typst compile $f.typ
printf '%-15s %s %s %s\n' $f "$(pdftotext $f.pdf - | grep Hallo)" \
"$(tr -d '\n' < $f.pdf | grep -a -o '/Type */Catalog[^>]*/Lang *([a-z]*)' | grep -o '/Lang.*')" \
"$(grep -a -o '<dc:language><rdf:Bag><rdf:li>[a-z]*' $f.pdf | sed 's/.*<rdf:li>/dc:language /')"
doneadjacent “Hallo” /Lang(en) dc:language en
apart “Hallo” /Lang(de) dc:language de
template “Hallo” /Lang(en) dc:language en
template-apart “Hallo” /Lang(de) dc:language de
typst 0.14.0 prints the same.
What I can see of the cause: eval_markup styles the rest of the markup with each set rule, and styled_with_map merges the styles into the rest when the rest is a single StyledElem. Adjacent, the two rules become one style list, and the locale is read from that list, where the later rule wins:
typst/crates/typst-eval/src/markup.rs
Line 41 in 9dfd3a0
| seq.push(eval_markup(vm, exprs)?.styled_with_map(styles)) |
typst/crates/typst-library/src/foundations/content/mod.rs
Lines 360 to 371 in 9dfd3a0
| pub fn styled_with_map(mut self, styles: Styles) -> Self { | |
| if styles.is_empty() { | |
| return self; | |
| } | |
| if let Some(style_elem) = self.to_packed_mut::<StyledElem>() { | |
| style_elem.styles.apply(styles); | |
| self | |
| } else { | |
| StyledElem::new(self, styles).into() | |
| } | |
| } |
typst/crates/typst-realize/src/lib.rs
Lines 627 to 631 in 9dfd3a0
| } else if elem == TextElem::ELEM { | |
| // Infer the document locale from the first toplevel set rule. | |
| if let RealizationKind::Document { info } = &mut s.kind { | |
| info.populate_locale(StyleChain::new(&local)); | |
| } |
With a blank line, the rest starts with the paragraph break, so each rule keeps its own StyledElem and the first one's language is taken. On main, visit_styled passes populate_locale the local styles chained with the outer ones, and the merged list is still among them. I haven't built main.
Operating system
Linux
Typst version
- I am using the latest version of Typst (0.15.1)
Activity
ZYZ666-RGB commentedon Nov 18, 2026
I'll start work on this now.
The later
set text(lang: ..)should win regardless of a blank line between the rules, including when a template applies a second language after the document sets one. I'll follow the analysis in the issue (eval_markup/styled_with_mapmerging), make the PDF/Langanddc:languageconsistent with the typographic language, and add tests for the adjacent, blank-line, and template cases.laurmaedje commentedon Nov 18, 2026
@ZYZ666-RGB Please keep in mind that we do not accept AI-generated contributions.
ZYZ666-RGB commentedon Nov 20, 2026
Thanks for the reminder. I won't open a PR on this issue.