-
-
Notifications
You must be signed in to change notification settings - Fork 873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Language-dependant font configuration #794
Comments
Won't that result in |
Indeed. Adding a to the regex would help somewhat, but it's probably still a bit brittle. |
Maybe using Font Family is a better choice. #set text(
font: ("Times New Roman", "SimSun"),
) The font |
While the idea of language-dependent font settings works for the language pair illustrated above, since Unicode code points for Chinese characters are not in English alphabets at all, it could be a bit challenging/infeasible for Typst to scale this solution to other language pairs like Chinese/Japanese, since they have overlapping Unicode code points. Other language pairs may have similar issues as well. To address this, maybe Typst needs to go a level lower: provide Unicode code range matching utilities (like CSS for web) so that users or package authors can configure fonts for different Unicode code points as they wish. |
I just wrote a detailed article related to this issue in Japanese, for a temporary solution. To summary, it's the same to poetlife's approach, but with the usage of Unicode Properties. For Japanese, because it uses three scripts #set text(font: "Noto Serif CJK JP") // Set base font
#show regex("[\p{scx:Han}\p{scx:Hira}\p{scx:Kana}]"): set text(font: "Noto Sans CJK JP") // Set Japanese font
*Typstにおける和欧混植のフォント設定法* For Chinese, we only need Han. #set text(font: "Noto Serif CJK SC") // Set base font
#show regex("[\p{scx:Han}]"): set text(font: "Noto Sans CJK SC") // Set Chinese font
*利用Typst中西文混排不同字体* |
After some research, I find out that the real problem is #1024 where The ideal descriptive approach of language selection is to firstly set the default language for each script used, then specify the language explicitly if the script is shared by multiple languages. As for now, this is not working because of the mentioned issue. #set text(font: "Noto Serif CJK SC", lang: "zh", script: "HanS")
// #show regex("\p{sc:Latn}"): set text(lang: "en") // You cannot use regex here because of the following reason below
#let en = text.with(lang: "en")
#let fr = text.with(lang: "fr")
#let ja = text.with(lang: "ja")
#let HanT = text.with(script: "HanT")
#show text.where(lang: "en"): set text(fill: red)
#show text.where(lang: "fr"): set text(fill: blue)
#show text.where(lang: "ja"): set text(fill: yellow)
#show text.where(lang: "zh", script: "HanT"): set text(fill: green)
中文中混有#en[English]和#fr[français]以及#ja[日本語]的时候,#HanT[我們默認拉丁文字是英文,漢字是簡體字中文,除非例外指定]。 For now, you can use
For the regex approach to set a default language / style, because of |
Say, if typ file is using unicode, it is possible to know which language any character belongs to.
Then can typst provide a method to set different font for different language.
The code seems does not work even for texts explicitly specified language:
The text was updated successfully, but these errors were encountered: