[Bug]: Chinese characters in inline formulas render oversized and eat the spacing around the fraction bar
What happened?
Inline LaTeX formulas that contain Chinese text as a standalone operand — e.g. \dfrac{现期量}{1+r}, where the CJK is not a subscript/superscript of a Latin symbol — render with the Chinese glyphs noticeably larger than the surrounding Latin math. The surplus ink is taken out of the clearance around the fraction bar: the CJK numerator sits almost on the rule, and that clearance collapses further as the content gets taller. Visually, the Chinese text spills out of the box the formula reserves for itself.
All four fractions below are on the same two lines of one document, in a single screenshot at one zoom, so the numbers are directly comparable:
| Fraction | Numerator ink | Clearance above rule | Denominator ink | Clearance below rule |
|---|---|---|---|---|
\dfrac{现期量}{1+r} |
26 px (CJK) | 11 px | 26 px (1+r) |
8 px |
\dfrac{增长量}{r} |
26 px (CJK) | 11 px | 16 px (r) |
16 px |
\dfrac{A}{1+r} |
23 px (Latin A) |
15 px | 25 px | 8 px |
\dfrac{A}{1-r} |
23 px (Latin A) |
15 px | 24 px | 8 px |
Two things stand out:
- A CJK numerator is taller than a Latin one (26 px vs 23 px) yet sits closer to the rule (11 px vs 15 px) — the clearance moves the wrong way with glyph size.
- The clearance below the rule follows the content ink, not the layout box:
r(16 px ink) keeps 16 px of air,1+r(26 px ink) keeps only 8 px. The glyph eats the gap instead of the box growing to fit it.
Distribution version
Windows x64 (Windows 11, build 26200)
App Version
0.27.4 (desktop client; the self-hosted server is also 0.27.4)
What browsers are you seeing the problem on if you're using web version?
N/A — reproduced in the AFFiNE desktop client for Windows.
Are you self-hosting?
- Yes
Self-hosting Version
0.27.4
Relevant log output
Anything else?
Steps to reproduce
- Self-hosted AFFiNE 0.27.4, open any document.
- Insert an inline formula whose numerator is CJK, e.g. type
/latexand write:基期量 = \dfrac{现期量}{1+r} = \dfrac{增长量}{r} - Put the Latin equivalent on the neighbouring line:
\dfrac{A}{1+r}. - Compare the clearance between the numerator glyphs and the fraction rule.
Expected: the space reserved around the fraction rule follows the glyphs that are actually rendered, so CJK content keeps the same clearance as Latin content — a Chinese numerator should not sit closer to the rule than a shorter Latin one, and a taller denominator should not shrink its own margin.
Actual: CJK ink is laid out against Latin fallback metrics; the surplus ink is absorbed by the rule clearance, so the Chinese text crowds the rule and appears to overflow the formula box.
Screenshots: attached in the comment below (one full formula line, and one same-screen comparison of a CJK numerator vs a Latin numerator).
Where this seems to come from (for triage, not a fix proposal)
The inline latex node renders with katex.render(latex, container, {displayMode: false}) (blocksuite/affine/inlines/latex/src/latex-node/latex-node.ts); the dependency is katex: ^0.16.27 (@blocksuite/affine-inline-latex/package.json). CJK characters are routed through KaTeX's cjk_fallback class, but their box metrics still come from KaTeX_Main, "Times New Roman" — so the fraction's num1/num2 clearance is computed for a Latin-sized glyph while the real CJK ink is taller than that box. The surplus ink is what eats the clearance.
I reproduced the same direction outside AFFiNE with a bare KaTeX 0.16.27 render (a CJK numerator keeps less clearance above the rule than a Latin one), so the metric mismatch comes from KaTeX rather than from AFFiNE-specific code. Filing it here because this is where the user-visible result lands, and a CJK-aware wrapper/padding on the inline-latex node would resolve it without waiting on KaTeX.
Why the obvious workarounds are not enough
- Reducing the formula font size also reduces the formula's total height, so the box/clearance problem stays — it merely gets smaller.
- Moving the Chinese into sub/superscript positions (e.g.
{}_{现期量}) shrinks the glyphs but changes the notation and has the same height side effect.
Both were tried across a 100+ formula study-notes document; neither fixes the layout, which is why this needs a fix on the rendering side.
Duplicate check
Searched open and closed issues for inline-latex / formula-spacing / CJK combinations. Related but not the same: #14219 (inline latex spacing), #14826 (\tag{} overlap), #10560 (symbol rendering), #15322 (pasted formulas not auto-formatted). The CJK-titled issues found (#13009, #14305, #13788, #12284, #2368) are all UI-translation or IME related, none about formula layout. Closest existing report is #14219; happy to close this as a duplicate if maintainers consider it the same root cause.
Is your content generated by AI?
Yes — this report was drafted with AI assistance and reviewed by the reporter before posting.
Source: toeverything/AFFiNE