I cannot quite figure out what it is in show rules. I have this example that I use to prevent line breaks on inline equations:
#show math.equation.where(block: false): it => {
box(it)
}
What is it exactly in this case? I am a bit puzzled that this just works, e.g. the correct math styling is still applied still applied to the inline equations.
The right part of this show rule is an unnamed function. The show rule docs have other examples; using a function and show-set are the two fundamental forms of show rules.
In the anonymous function, it is the parameter and is filled by the show rule with its target: the element that matched the show rule. In this case, the function would be called once for every non-block equation.
So in this case you can see that it is an equation, and you could access some of its properties within your function, or use those properties as part of a filter (the .where in the first part of the show rule).
I’d like to note also that the name it is not required, it’s just a common choice (though I’m not sure why). The following all produce identical results:
In the third case no name is given, but that’s ok because when the show rule is applied to the equation, it is looking for a function to pass what it finds to. In this case the show rule finds/matches an equation, then that equation is passed directly to repr which accepts a single piece of content as a valid way to call the function.
Edit:
The tooltips that the web app (and Tinymist) provide are also very helpful. Hovering my mouse over the it shows the same info that repr does:
This would be equivalent to using it => box(fill: red, it)
Yes, thanks for pointing that out. I forgot to mention that and it’s commonly misunderstood.
As far as I know, “it” is just the English word, i.e. it roughly means “the thing”. Another meaning that I’ve seen is “item” but I think that has a bit less attestation. I also like to use “body”, especially for templates intended to be called as “show-everything” rules:
// main.typ
#import "template.typ": my-template
#show: my-template(config: true)
This is the body
// template.typ
#let my-template(
config: false,
// ... and other options
) = body => {
// ... apply some styling
body
}
(the example is a bit more complex than it needs to be, as my-template is a function returning a function, but I wanted to write the example like I would actually write my templates)
exactly to avoid the with it’s a bit more effort (time and mental load) for the template author, but saves a bit for the template consumer. And hopefully the template will be used a bunch, so prioritizing that hopefully pays off
I prefer the plain version that requires a with: I’m afraid that hiding it will obscure things for new users and push them in a “I don’t know what this is but it magically works” state of mind instead of learning the basics of the scripting language.
But there’s probably no right answer, it’s all a bit subjective…
I had the "I don’t know how it works, guess I’ll just write the with " moment .
To be honest, the documentation and the tutorials are not quite there yet where I am able to just search for things and have them easily explained. Especially on google the info is kind of hard to find.
Just mentioning this as I didn’t see it mentioned anywhere below. it is just a variable name. You can use any name that you want. It doesn’t have to be it.