Why the definition of "show regex" doesn't work in a function?

This is because show only works on content within its scope. In your example, this scope is the interior of the __sugar() function definition.

The principle of show is that it will take everything that matches its selector below and within its scope, and process it using the function you specify. So when you call __sugar(), show did nothing because there is nothing else in it’s scope.

To fix this issue, you need to write another show in the scope you want. For example:

#let __sugar(content) = {
  show regex("=+/?(.+)"): it => {
    it.fields()
  }
  content
}

#let my-template(
  body
) = {
  [My template]

  show: __sugar

  body
}
1 Like