-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
bugSomething isn't workingSomething isn't workingcjkChinese, Japanese, Korean typography.Chinese, Japanese, Korean typography.
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcjkChinese, Japanese, Korean typography.Chinese, Japanese, Korean typography.


