How to use different CJK font weight in different elements but not affect the latin characters?

Hi all,

I’m trying to use different weight for CJK characters in different elements. For example, use “bold”-weight of font Source Han Serif in heading, but “regular”-weight of Source Han Sans in strong. But latin characters are shown with “bold” weight in both cases.

I found it impossible to achieve by setting show regex("\\p{Han}" suggested in this post as the regex show rules will apply globally. If I set such a rule in one element, it would affect all after that element.

Are there any solutions?

Regex show rules don’t need to apply globally, you can apply them to specific elements or scopes.

#let b-to-p(body) = {
  show regex("[Bb]"): it => (B: "P", b: "p").at(it.text)
  body
}
// now we can apply the rule where we want to
#b-to-p[
  Banana and biscuits.
  #table[Abc.]
]
#show heading: b-to-p
= Banana
But this text is safe from modification of b's.
1 Like

It depends on whether the font of the heading or strong is the same as the main text. Bluss gives the latter case, and here’s the former case.

#set page(width: auto, height: auto, margin: 1em)

#set text(
  lang: "zh",
  font: (
    (name: "Libertinus Serif", covers: "latin-in-cjk"),
    "Noto Serif CJK SC",
  ),
  top-edge: "ascender",
  bottom-edge: "descender",
)

#show strong: set text(font: (
  (name: "Libertinus Serif", covers: "latin-in-cjk"),
  "Noto Sans CJK SC",
))
#show strong: it => {
  show regex("\p{Han}"): set text(weight: 100)
  it
}


= Heading 标题

text正文*强调 strong*

#set strong(delta: 0)
*strong 强调*

Besides, I recommend replace show-func with show-set whenever possible, especially for template authors.
The reason is that show-func rules are hard to override. See Which show rule takes precedence? for explanation.


Maybe you could install SourceHanSans-Regular alone (without other weights)…

1 Like

Thanks for your reply. However, the perform I observed is not as stated as that in documents. Perhaps it is caused by logic error in my code.

Many thanks! You remind me that I set weights globally unexpectedly in a no-selector show and it is hard to override!! I finally figured it out.

1 Like