Touying: How can I access self in an ad-hoc way?

I have a Touying (0.5.x) template that sets the table stroke in init:

  config-methods(
    init: (self: none, body) => {
      set table(stroke: self.colors.neutral-dark)

      body
    },
  ),

However in a table I don’t want strokes everywhere and have to use a stroke parameter like this:

  table(
    stroke: (x, y) => if x < 2 and y < 2 { 1pt },
    [...],
  )

This does not preserve the color, I need 1pt + self.colors.neutral-dark. However, I don’t know how I can access self in a “plain old slide”.

I assume Touying must have a mechanism to get access to self in such cases. How does that work?

I found two ways to do it, documented in Complex Animations. The first is touying-fn-wrapper:

#touying-fn-wrapper((self: none) => {
  table(
    stroke: (x, y) => if x < 2 and y < 2 {
      1pt + self.colors.neutral-dark
    },
    [...],
  )
})

The page points out:

However, this does not work in all cases, for example if you put uncover into the context expression, you will get an error.

The other option is slide:

#slide(self => {
  table(
    stroke: (x, y) => if x < 2 and y < 2 {
      1pt + self.colors.neutral-dark
    },
    [...],
  )
})
2 Likes