How does one of these rules avoid show rule recursion?

I am a little confused about the mechanism behind show rules, what is the difference between the following two ?

  show text.where(weight: "bold"): it => {
    show regex("\p{Han}"): set text(stroke: 0.8pt)
    it
  }
 // Will cause infinite recursion
    show underline: it => {
      show text.where(weight: "bold"): set text(fill: blue)
      it
   }
  // works well

Can someone explain that?

Could you provide a full example? I can’t reproduce what you said with neither typst v0.13 nor v0.14.

My full code
#set page(height: auto, width: 240pt, margin: 30pt)

#set text(font: "Noto Serif CJK SC", lang: "zh")

#show text.where(weight: "bold"): it => {
  show regex("\p{Han}"): set text(stroke: 0.8pt)
  it
}

#underline[*人 A c*]

#show underline: it => {
  show text.where(weight: "bold"): set text(fill: blue)
  it
}

#underline[*人 A*]

In any case, I believe all show text: function rules are essentially hacks, because the semantic carried by text is very weak so it can match everything.
Certain show text: function rules (#5140, #5271) might crash the compiler, and they are not even considered as bugs.

1 Like


something like that, the first one crashed the compiler, and if I changed the code to this

show regex("\p{Han}"): it => {
    show text.where(weight: "bold"): set text(stroke: 0.8pt)
    it
}

it works well :face_with_monocle:

1 Like

Okay I reproduce it this time. It looks like it’s exactly #5271 I mentioned above?
(I wanted to link #5140 in that post. But somehow, I pasted the wrong link #5271… I’m editing that post and keeping both links.)

Besides, you can put typst typc after ``` to make the code highlighted on this forum.

(typc in this case, since there are no leading #s. typ/typst is already the default and would usually work out of the box)

1 Like