Repository navigation
Description
Description
Some fonts provide their names in multiple languages.
For example, each Source Han Sans/Serif font has both an English name and a localized name, as shown in following table extracted from Adobe's font readme.
It would be good if typst supports selecting font via any name.
Relates-to: #2098
Note
It has to be Source Han Sans/Serif released by Adobe, not Noto Sans/Serif CJK released by Google.
Google also releases fonts with localized name table strings, but the actual strings are identical to the English-language ones.
Use Case
At present, typst supports selecting font via only a single name. Sometimes it's the English name, and sometimes it's the localized name. It is difficult to predict which one it is.
As an example of this chaos:
- Source Han Sans SC (思源黑体) can only be selected by
"Source Han Sans SC". - Source Han Sans TC (思源黑體) can only be selected by
"思源黑體". If you specify"Source Han Sans TC", you'll get a font-not-found warning.
The following is a screenshot of typst fonts shared by Runge on 2025-11-14. You can see that TC is somewhat unique. All fonts use English names, except TC.
2026-04-14 update:
A (A is a username) complaints that he/she installed a font whose name in Windows Font settings is in Simplified Chinese.
However, its name in Typst is in Traditional Chinese, and the font won't appear in the completion menu unless the Traditional Chinese charater is typed explicitly.
As a result, it's really hard for A to select that font, because A doesn't use Traditional Chinese and hence can't type that character.
Cause of the inconsistency
The original Chinese version 中文原版
Adobe 发布的思源黑体 Source Han Sans 提供了简体中文 SC、繁体中文 TC 等版本。在 Typst 中使用时,前者要写“Source Han Sans SC”,后者却要写“思源黑體”而非“Source Han Sans TC”。
这是因为 Adobe 在字体中提供了英文、中文(繁简之一)两版字体名,Typst 会选择靠前的名字。那么为什么 SC 版英文名靠前,而 TC 版中文名靠前呢?
根据 OpenType 规范,名字要按照语言 ID 排序。对于包括思源在内的很多字体来说,这个语言 ID 是微软的 Windows Language Code Identifier (LCID)。
LCID 用数字代码表示语言,大致低位对应语言,高位对应地区。于是 zh-TW = 0x0404, en-US = 0x0409, zh-CN = 0x0804。可排序还是从高到低排呀,于是繁体中文在英文前面,英文在简体中文前面……
Adobe provides both English and Chinese (either traditional or simplified) names in the font, and Typst will choose the earliest name with find_map.
typst/crates/typst-library/src/text/font/book.rs
Lines 313 to 328 in 4117371
| /// Try to find and decode the name with the given id. | |
| pub(super) fn find_name(ttf: &ttf_parser::Face, name_id: u16) -> Option<String> { | |
| ttf.names().into_iter().find_map(|entry| { | |
| if entry.name_id == name_id { | |
| if let Some(string) = entry.to_string() { | |
| return Some(string); | |
| } | |
| if entry.platform_id == PlatformId::Macintosh && entry.encoding_id == 0 { | |
| return Some(decode_mac_roman(entry.name)); | |
| } | |
| } | |
| None | |
| }) | |
| } |
So why does the English name come first in SC, but the Chinese name come first in TC?
According to the OpenType specification, names should be sorted by language ID. For many fonts, including Source Han Sans, this Language ID is Microsoft's Windows Language Code Identifier (LCID).
LCID represents a language with a numeric code, with the lower bits roughly corresponding to the language and the higher bits to the region. So zh-TW = 0x0404, en-US = 0x0409, zh-CN = 0x0804.
However, the IDs are sorted as numbers, and highers bits matter more. So Traditional Chinese (TC, zh-TW) comes before English (en-US), and English comes before Simplified Chinese (SC, zh-CN)...
Why this is discovered so late
Most people only use one version of Source Han, so won't encounter such inconsistency.
I noticed it while I was debugging #7396. I shared it in the Chinese QQ chat group and everyone was surprised. But after testing, we found that the behavior is reproducible.
Reference implementations
MS Paint, Word, etc. only show localized names.


Activity
RungeCC commentedon Nov 25, 2025
encoding_iddepends onplatform_id), so it maybe weird if a certain font contains some localzied name encoded in, e.g.,Macintosh_Korean(I think there's no way Typst could support all this legacy encodings...), user can see it with system font manager (or, with MS Word? not, sure(, but can not actually use this name as font name in Typst. This shouldn't be a major issue for common scenarios—for example, every localized name in the Source Han fonts is still encoded within the Unicode BMP—though it might cause some inconsistencies in edge cases.typographic_familyis designed to work with English language, so if using localized name it may break -- although it is already riddled with problems as it is. Since Typst relies the result of it to distinguish fonts (as key ofFontBook), so I wander that if allow multi-language family name may cause more ambiguity.Possible solutions:
font_namereturn a single string inEnglish (United State)if possible (otherwise localized string). After that, family name given by Typst will be more consistent, else part offont.rscould remain unchange. However, after so Typst can no longer find"思源黑體"but only"Source Han Sans TC", cuasing compatiblity issue.font_namereturn a list containing all strings matchingname_id, where the first one should be inEnglish (United States)if possible. UseEnglish (United States)name asFontBookkey (aftertypographic_familystuff) if possible, and also store each localized (decodeable) string, then it's possible to find font through localized name, but may cause some inconsistency between user provided family name and Typst used name (can be introspected with#context text.font).I think Option 2 is more feasible (although the changes to
book.rsare larger), or should we wait for the font object design? CC: @laurmaedje.Appendix: name mapping of
Source Han Sans.ttc:docs: Regular minor updates
sungodmoth commentedon Feb 22, 2026
For what I'm pretty sure is the same reason, Noto Sans Egyptian Hieroglyphs is accessible only as
"Noto Sans EgyptHiero"(although it provides both this and"Noto Sans Egyptian Hieroglyphs"as family names). This issue is thus not exclusive to fonts with names in multiple languages.YDX-2147483647 commentedon Feb 22, 2026
The story of Noto Sans Egyptian Hieroglyphs is a bit different.
It relates to different name IDs, rather than different language IDs.
Raw data
Version: https://github.com/notofonts/egyptian-hieroglyphs/releases/tag/NotoSansEgyptianHieroglyphs-v2.002