Why does a show rule add extra spacing?

Hi,

First time poster so hopefully I am doing this right. I am trying to add a show rule to my CV so that it bolds my name every time it shows up in a citation. It is working, but it is also adding an extra space. Any idea what is going on here?

#show regex("Warkentin MT"): name => [
  #name
]

+ Warkentin MT, Ruan Y, Hutchinson JM, Brenner DR. openmpp: An R package for dynamic microsimulation modeling using OpenM++. Journal of Open Source Software, 10(109), 7435, https://doi.org/10.21105/joss.07435.

image

Notice the extra space between MT and the trailing comma. I don’t think I need the regex, I can just use "Warkentin MT" but this has no effect on the extra spacing anyway.

The same issue happens when I use the actual show rule I want:

#show regex("Warkentin MT"): name => [
  #set text(weight: "bold")
  #name
]

I just provided the minimal code above to showcase the issue.

1 Like

This happens because you are using square brackets for the scope inside the show rule, see Scripting – Typst Documentation. The replacement therefore starts at the opening bracket, which inserts the extra space before and after “Warkentin MT”. You can see the same effect if you tightly wrap the #name in the square brackets, and then add spaces again around #name.

#show regex("Warkentin MT"): name => [ #name ]

If you just want to make the text bold, you could therefore use the following show rule

#show regex("Warkentin MT"): name => text(weight: "bold", name)

For general show rules, you can prevent the issue by using curly braces to create a code-style scope

#show regex("Warkentin MT"): name => {
  set text(weight: "bold")
  name
}
3 Likes

Amazing, thanks @janekfleper.