A blank line between two `set text(lang: ..)` rules changes the PDF's language

Aperta
#9,050 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start by reading eval_markup in crates/typst-eval/src/markup.rs, then trace how StyledElem styles are merged in crates/typst-library/src/foundations/content/mod.rs and how visit_styled calls populate_locale in crates/typst-realize/src/lib.rs. Reproduce the adjacent and blank-line cases with PDF output and add regression coverage for both. Done means the declared PDF language is consistent regardless of the blank line.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

styling syntax
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 /')"
done
adjacent        “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:

https://github.com/typst/typst/blob/9dfd3a08500b7896045f907433cf7b4b02434fad/crates/typst-eval/src/markup.rs#L41

https://github.com/typst/typst/blob/9dfd3a08500b7896045f907433cf7b4b02434fad/crates/typst-library/src/foundations/content/mod.rs#L360-L371

https://github.com/typst/typst/blob/9dfd3a08500b7896045f907433cf7b4b02434fad/crates/typst-realize/src/lib.rs#L627-L631

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)
Lingua principale
Rust
Stelle
57.2k
Fork
1.8k
Merge medio
1g 17h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di typst/typst

Tutte le issue di typst/typst

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.