In Chinese we call it ‘着重号’, how to implement it?
I have tried with underline, but not cannot get the same effect.
In Chinese we call it ‘着重号’, how to implement it?
I have tried with underline, but not cannot get the same effect.
Refer to The Raindrop-Blue Book (Typst中文教程)
Sample code:
#set text(font: "Noto Serif CJK SC", lang: "zh")
#show strong: content => {
show regex("\p{Hani}"): it => box(place([·], dx: 0.34em, dy: 0.75em) + it)
content.body
}
牛背上牧童的*短笛*,这时候也成天在*嘹亮*地响。
Output is:
But the parameters of dx and dy should be adjusted according to the actual Chinese font you’re using.
Thanks!
This only works without #set par( first-line-indent: (amount:2em, all: true), )
When added first line indention, we get strange result:
with code
#set par(
first-line-indent: (amount:2em, all: true),
)
#set text(font: "Noto Serif CJK SC", lang: "zh")
#show strong: content => {
show regex("\p{Hani}"): it => box(place([·], dx: 0.34em, dy: 0.75em) + it)
content.body
}
牛背上牧童的*短笛*,这时候也成天在*嘹亮*地响。
This seems to work:
#show strong: content => {
show regex("\p{Hani}"): it => [#it#box(place([·], dx: -0.5em, dy: -0.1em))]
content.body
}
Thanks for then help!
The above solution works in your case, but the effect depends on the font heavily. Moreover, it will disrupt text search in the PDF.
The following solution leverages underline.stroke, so it keeps PDF search okay. However, this solution does not work if you have set text(tracking: …).
#show strong: body => {
show regex("\p{sc=Hani}+"): s => {
underline(s, offset: 3pt, stroke: (
cap: "round",
thickness: 0.1em,
dash: (array: (0em, 1em), phase: 0.5em)
))
}
body
}
We can conclude that this feature is so complicated that it has to be natively supported by Typst.
Previous discussions in the Chinese community are recorded in the following issue.
I agree, it will destroy the search.
Here is a solution that won’t:
#show strong: content => {
show regex("\p{Hani}"): it => [#it#box(place(circle(fill: black, width: 0.12em), dx: -0.55em, dy: 0.1em))]
content.body
}
Though, I agree, it is not 100 % optimal.