How to connect `where`-clauses with `or`?

It may be a trivial question, but I have no clue on how to connect several where-selectors with or. I have the following show-rule

#show outline.entry.where(level: 2): it => {

and would like to apply it not only to level: 2, but also to level: 3. I’ve tried different variations with or., but non of them worked.

1 Like

You have to basically re-specify the full element, like so:

#show outline.entry.where(level: 2).or(outline.entry.where(level: 3)): ...
3 Likes

Ah thanks, indeed, that does the trick :slight_smile:

Hey @Roland_Schatzle, welcome to the forum! I’ve changed your question post’s title to better fit our guidelines: How to post in the Questions category

For future posts, make sure your title is a question you’d ask to a friend about Typst. :wink:

Note that you can also use a loop (or more precisely, the array.map() method) to generate the selector:

#show selector.or(..(2, 3).map(level => outline.entry.where(level: level)): ...

this makes it easier to specify multiple levels

4 Likes

That’s an interesting approach! But I have difficulties understanding it. What is the precedence of the operations or, .. and map?

Let’s break it down:

// this is a function that takes a number as a parameter,
// and returns a selector for a specific outline entry level
#let mapper = level => outline.entry.where(level: level)
// this is an array of multiple selectors, created by taking
// each number in the original array, giving it to the function,
// then putting all the results together in a new array
#let levels = (2, 3).map(mapper)
// this is the combination of all the selectors. The or()
// function takes any number of parameters, and .. separates
// the array elements into separate parameters
#let complete = selector.or(..levels)
// this selector is used for the show rule
#show complete: ...
2 Likes

Ok, thanks, now I understand it in detail!