How to prevent show rule on certain content?

I have a show-set rule that will affect all headings. But there are some special headings that I don’t expect to affect. What should I do?

For example, how to prevent those special headings below from being affected by #show heading: set text(red):

#show heading: set text(red)

= heading

= heading

= heading // special heading

= heading

= heading

= heading // another special heading

I would like to add a if rule in the show-set rule, but I don’t know how to flag them in code.

I think it’s more common to do this:

#outline()
#show heading: set text(red)

= heading

= heading

// Override the original style
= #set text(black); heading

= heading

= heading

// Another way to do so
#[
  #show heading: set text(black)
  = heading
]

= heading

This is definitely not common. At the very least, it should be = #text(black)[heading]. Either way, since it’s in the heading’s body, the outline entry will also have the same styling applied, unlike the show-set rules.

1 Like

Thank you for your reply!
Unfortunately, it can’t work nicely in my project because I have used a function to change the color. And I match the content by string directly. Like:

show "sth": it => text(red, it)

(fixed the code highlight to typc)

The colored text was in the innermost layer, so I have no way to override it. That is the reason why I am looking for a way to flag one content to prevent coloring.

This fits pretty closely to your request:

#show heading: it => {
  set text(red) if not (it.has("label") and it.label == <special>)
  it
}

= heading

= heading

= heading <special>

= heading

= heading

= heading <special>

Your example uses a show: set rule which is perferred, this solution does not. It has a function in order to check the special label.

If you can somehow switch your logic around, this would be more performant:

#show heading.where(label: <special>): set text(black)
1 Like

If you show code mode snippet, use typc language tag in the info string.

You can also do

#show heading: it => {
  set text(red) if it.at("label", default: none) != <special>
  it
}
1 Like

Thanks for your reply!
This does solve my problem.