Hello typst authors and developers!
We recently updated Chinese Layout Gap Analysis (clreq-gap) for Typst to v0.14.0.
As introduced before, this is a document describing gaps or shortcomings in typst for the support of the Chinese script, including text layout and bibliography.
1. Setting Chinese font in mathematical equations
Typst v0.14.0 changes the way of setting Chinese font in math.
Setting Chinese font is necessary, because the default math font (New Computer Modern Math) does not cover Chinese characters like (定义).
Without proper configuration, they will either become tofus □□ as shown below, or fallback to the Chinese serif font with the shortest name installed on the system (KaiTi for most people).
In v0.13, text handling is math was quite limited, and the way of setting Chinese font actually “depended” on several bugs.
Thanks to mkorje and other contributors, the situation has improved significantly in v0.14.0.
- It’s now possible to mix multiple math fonts in a single equation.
- Texts (
$"x"$) and variables ($x$) in math are treaded more equally. - Font coverages are now respected in math.
- Setting fonts repeatedly with different coverages is now effective.
So the new recommend way to set Chinese font in math is:
#show math.equation: set text(font: (
(name: "New Computer Modern Math", covers: "latin-in-cjk"), // Math
(name: "Source Han Serif SC", covers: regex(".")), // Chinese
"New Computer Modern Math", // Math
))
$hat(alpha)(f) = f(alpha) "(同上,α–map的“定义”)"$
$ f(alpha) #[或者*任意*内容 _α–map_ $alpha$–map] $
$ cases("Math" 1 I l, "正文 1Il") $
- Use New Computer Modern Math for most characters it contains, except a few punctuation marks shared by Latin and Chinese, including
“”. - For uncovered characters, use Source Han Serif SC.
- Use New Computer Modern Math for typographic metrics that controls complex positioning and spacing in math.
This specific order/repetition/syntax is derived from the following propositions.
- Typst use the first font without
coversas the base math font. It has to provide math metrics, otherwise “warning: rendering may be poor”. - There should be a math font before the first Chinese font. Otherwise, the
{ofcaseswill use the Chinese font, but it does not support being stretched. - Punctuation marks shared by Latin and Chinese should use the Chinese font.
If you prefer to use different fonts for Latin and math, or don’t use punctuation marks in math, there exist other solutions.
You can use the website Typst set font to generate the code. This website is planned to be moved to Typst Chinese community’s GitHub organization after completion.
2. Bibliography improvements
Bibliography has always been a painful area.
As shown in the summary below, it has the most red and orange dots. There are basic demands that lack nice and clean workarounds.
Bibliography has the highest degree of automation, but at the cost of increasing the difficulty to tweak subtleties. If Typst does not something natively, it is really hard to patch it on our own.
The good news is that we are improving it bit by bit, and Typst 0.14.0 has made some leapfrog progress.
2.1 All elements in the CSL spec needed by Chinese CSL styles can be loaded
The Citation Style Language (CSL) is an XML-based format to describe the formatting of citations, notes and bibliographies. You can use it to customize bibliography.style.
However Typst v0.13.1 did not recognize certain elements in CSL 1.0.2 Specification.
For example, when you were trying to use 历史研究.csl, the old Typst would refuse to load it and throw the following scary error:
Failed to load CSL style (unknown variant page, expected one of chapter-number, citation-number, collection-number, edition, first-reference-note-number, issue, locator, number, number-of-pages, number-of-volumes, page-first, part-number, printing, printing-number, section, supplement-number, version, volume)
It is caused by <number variable="page"/> in 历史研究.csl. Even if you don’t actually use this type of citation, it will prevent you from loading the CSL.
Typst v0.14.0 no longer throws that error.
According to our survey, all ~300 Chinese CSL styles can now be loaded by new Typst, after removing non-standard elements.
2.2 Citation numbers are no longer flying over their brackets
As mentioned in the previous post, the Chinese convention for citation numbers is [1]. In Typst v0.13.1, 1 may fly over [], and the severity depends on the specific configuration:
Typst v0.14.0 fixes the positioning issue of superscripts in #5777, including these [1] created by the cite function.
Now both of the above examples become sane:
However, that fix triggered another issue about the interaction between superscripts and CJK-Latin spaces (#7113 and w3c/clreq#713). Fortunately, we managed to correct the behaviour before the release deadline.
2.3 The footnote citation style is now usable
The national standard for bibliography in China specifies three citation styles: numeric 顺序编码, author-date 著者-出版年, and note/footnote 注释/脚注.
In Typst v0.13.1, footnote styles were totally broken, because Typst didn’t pass correct info to CSL. You may get awkward results like ;;., as shown below.
Typst v0.14 now corrects it. Those ;;. becomes 同上 (meaning: same as above, ibid.) as expected.
3. Fixed CJK-Latin-spacing at manual line breaks
Typst v0.14.0 also fixes a minor issue on text spacing.
Final notes
-
The document is written in typst and hosted open source (Apache 2.0).
Thanks to the new Typed HTML API, we deleted 1410 lines when updating to v0.14.
-
Discussion and contributions are welcomed. You can comment in English or Chinese in that repo, but please use English when replying here (due to forum rules).
Thank you for your attention!










