#Inner workings of set and show rules

13 messages · Page 1 of 1 (latest)

quiet palm
#

Hey i wanted to know, as i havent been able to find anything about it on the docs or forum, how does the show rule work in practice?
specifically in the case of a show-set rule like so:

#show heading: set text(blue)

== test heading

with a normal set rule the logic makes sense to me as described in the docs: simply setting default values for parameters of a function in the current scope(im assuming here typst is perhaps interpreted line by line and thus also beyond scope thats why only things after a set rule are affected).

But with show rules how do they actually work? in the example above i understand that the show rule probably receives some kind of collection of all instances that the selector applies to, but considering that a heading doesnt have a field/parameter for text how is the text affected? Does it simply take the content in each instance of a heading, apply the text function on it and then replace the content in the instance with the content returned from the text function?

Does it instead relegate creation of content until after everything is compiled?

Do all instances that a selector applies get passed as content to the applying function or do they get passed some other way?

quiet palm
#

Inner workings of set and show rules

quiet palm
#

^

cerulean wave
#

This is different from show heading: it => ...

#

You can think of it as a set rule that only applies to headings and stuff that the heading turns into

#

(its "children")

#

In particular the heading element has a built-in show rule which places its body

#

And so the set rule will apply to the body, which has text

quiet palm
#

But how does the show rule affect all instances of an element?
Given that a show rule can recieve the instance in question and then use it in a function how is the instance passed along?

cerulean wave
#

but basically it will apply an algorithm where it will go from the top of the element tree to the bottom, invoking show "recipes" on each one as needed, replacing one element in the tree with whatever the show rule returned

#

a bit complicated to explain here but the code is there

#

:p