Repository navigation
Closed
Description
Original title: cjk-latin-space + manual linebreak + align(center) ⇒ Unexpected left shift
Description
If the line is broken manually between a CJK and a Latin character, then typst will insert an extra CJK-Latin space. This space becomes noticeable when text is aligned to the right or center.
In the following example, the text 国国 is intended to be horizontally centered, but it appears slightly shifted to the left.
#set text(font: "Noto Serif CJK SC")
#box(width: 2.3em, stroke: (x: green), align(center, [国国\ T T]))This issue only occurs when
- cjk-latin-spacing is enabled (which is the default),
- and the line break is manually created by
linebreak()or\.
This issue is NOT related to the linebreaks algorithm, as it occurs in both #set par(linebreaks: "simple") and #set par(linebreaks: "optimized").
More examples
Full code
#let test(body, width: 2.3em) = box(width: width, stroke: (x: green), align(
center,
body,
))
#set page(width: auto, height: auto, margin: 1em)
#set text(
font: "Noto Serif CJK SC",
lang: "zh",
top-edge: "ascender",
bottom-edge: "descender",
)
#set raw(lang: "typc")
#show raw: set text(font: ("DejaVu Sans Mono", "Noto Serif CJK SC"))
#set table.hline(stroke: 0.5pt)
#table(
columns: 3,
stroke: none,
align: (horizon, center + horizon, horizon),
..(
([✅], `[国国TT]`),
table.hline(),
([❌], `[国国\ TT]`),
(
[❌],
`[国国] + linebreak() + [TT]
// Equivalent to the above`,
),
(
[❌],
`text(cjk-latin-spacing: auto)[国国\ TT]
// Equivalent to the above`,
),
([✅], `text(cjk-latin-spacing: none)[国国\ TT]`),
table.hline(),
([❌], `[国国\ T国]`),
([✅], `[国T\ T国]`),
([✅], `[国T\ 国国]`),
([✅], `[国国\ 国国]`),
)
.map(row => if type(row) == array and row.len() == 2 {
let (ok, body) = row
(ok, test(eval(body.text)), body)
} else { row })
.flatten(),
table.hline(),
[❌],
test(width: 2.3em)[国国\ TT],
[`[国国\ TT] + 2.3em`, where `2.3em` is width],
[❌], test(width: 2.5em)[国国\ TT], `[国国\ TT] + 2.5em`,
[❌], test(width: 2.8em)[国国\ TT], `[国国\ TT] + 2.8em`,
[❌], test(width: 3.5em)[国国\ TT], `[国国\ TT] + 3.5em`,
)Additionally, the cjk-latin space also affects align(end).
Links
- A bit related to CJK-latin glues stretch only before latin characters #6062.
- Relates to Whitespace Between CJK & Latin Not Working Before Line Break #2538.
- Included in clreq-gap for typst.
Reproduction URL
No response
Operating system
Windows, Web app
Typst version
- I am using the latest version of Typst
Reacted by ᡥᠠᡳᡤᡳᠶᠠ ᡥᠠᠯᠠ·ᠨᡝᡴᠣ 猫
Reacted by Kevin Stephen



Activity
[-]cjk-latin-space + manual linebreak + align(center) ⇒ Unexpected left shift[/-][+]Unexpected cjk-latin space at manual linebreaks[/+][-]Unexpected cjk-latin space at manual linebreaks[/-][+]Unexpected cjk-latin space at manual line breaks[/+][-]Unexpected cjk-latin space at manual line breaks[/-][+]Redundant cjk-latin space at manual line breaks[/+]docs: citation form, auto hanging indent, cjk-latin space at `\ `
YDX-2147483647 commentedon Jul 2, 2025
Another mystery: the behaviour in show + eval is inconsistent.The reason is that
cjk-latin-spacingisnonein show + eval.Outdated example
[-]Redundant cjk-latin space at manual line breaks[/-][+]Redundant CJK-Latin space at manual line breaks[/+]docs: citation form, auto hanging indent, cjk-latin space at `\ `
docs: citation form, auto hanging indent, cjk-latin space at `\ `
docs: citation form, auto hanging indent, cjk-latin space at `\ `
bluss commentedon Jul 2, 2025
@YDX-2147483647 as an aside but I think that's because the raw element changes cjk-latin-spacing.
typst/crates/typst-library/src/text/raw.rs
Line 482 in 22a57fc
It also changes
langto"en"which is another setting to keep track of in this context - all raw's changes need to be reset/counteracted unfortunately in this scenario.Fix CJ-Latin space at manual line breaks
docs: typst/typst#6539 is now fixed