I need to check whether the text is being laid out rtl or ltr. In other words, I need to know whether the current language is written ltr or rtl.
If I do
context text.dir
I get auto
.
How can I get rtl
or ltr
?
I can check it using text.lang
, but then I’ll need to have the list of all rtl languages, which seems inconvenient.
Andrew
April 6, 2025, 12:46pm
2
I also faced this problem before Add default typst implementation code where possible · Issue #5095 · typst/typst · GitHub . You probably should open an issue about this.
// crates/typst-library/src/text/lang.rs
#let get-text-dir() = {
if text.dir != auto { return text.dir }
let rtl-langs = (
"ar",
"dv",
"fa",
"he",
"ks",
"pa",
"ps",
"sd",
"ug",
"ur",
"yi",
)
if text.lang in rtl-langs { rtl } else { ltr }
}
// #set text(dir: rtl)
// #set text(lang: "pa")
#context get-text-dir()
Also, please use the appropriate language identifier for code block in forum posts, as explained in How to post in the Questions category .
If your question pertains to a bit of Typst markup you have problems with, put it in the question body! You can syntax-highlight Typst code by wrapping it in ` ```typ … ````. It will then look like this:
#set font(size: 12pt)
Hello from *Typst* at $ pi.var + 1 $ o'clock!
If you need to highlight a code or math mode snippet instead, the language tags typc
and typm
do that, respectively.
1 Like