Revoking rules
Most rules can be temporarily revoked in a certain scope. This is especially useful for show rules, which often aren't easy to undo, unlike set rules. This can also be used to place an element while ignoring set rules if necessary. There are lots of possibilities!
This is also useful for templates: they can specify a default set of rules which the user can then revoke if they want without changing the template's source code.
Naming rules
The first step to revoking a rule is giving it a name by using e.named(name, rule)
. This is the name we'll use to indicate what to revoke:
#import "@preview/elembic:1.1.1" as e
#let elem = e.element.declare(/* ... */)
#show: e.named("removes elems", e.show_(elem, none))
// This is removed
#elem()
// This is removed
#elem()
You can assign multiple names to the same rule (e.named(name1, name2, ..., rule)
). Revoking any of them will revoke the rule.
In addition, the same name can be shared by multiple rules. Revoking that name revokes all of them. This can be used to create "groups" of revokable rules.
Filtered rules need some extra attention regarding naming:
-
e.named("name", e.filtered(filter, rule))
will assign"name"
toe.filtered
, but not to eachrule
created with this filter.- In this case, revoking
"name"
will stop any newrule
from being applied, but will not revoke an already appliedrule
in this scope.
- In this case, revoking
-
e.filtered(filter, e.named("name", rule))
will assign"name"
to each newrule
created, but not toe.filtered
. This is fairly unusual. -
e.named("name", e.filtered(filter, e.named("name", rule)))
will assign"name"
to bothfiltered
and each new copy ofrule
.- This is usually recommended, as revoking
"name"
will both stoprule
from being applied and revoke an already activerule
.
- This is usually recommended, as revoking
revoke
rules
Next, let's say we want to stop a rule from being applied in a certain limited scope. We can then use e.revoke("name")
to temporarily revoke all rules with that name.
For example, let's temporarily cancel the show rule from the previous example to show just one element:
#import "@preview/elembic:1.1.1" as e
#let elem = e.element.declare(/* ... */)
#show: e.named("removes elems", e.show_(elem, none))
// This is removed
#elem()
#[
#show: e.revoke("removes elems")
// This is shown!
#elem()
]
// This is removed
#elem()
reset
rules
Reset rules are more drastic and allow temporarily revoking all previous rules - named or not - in a certain scope.
The effect can be restricted to rules targeting only a single element, or (if nothing is specified) applied to all elements at once. Use with caution, as that may have unintended consequences to 3rd-party elements.
Reset rules targeting specific elements will stop active filtered rules targeting those elements from applying new rules, but will not revoke already applied rules unless they also target the same elements.
Consider the example below:
#show: e.set_(container, fill: red)
#show: e.set_(container, stroke: 5pt)
#container[This has red fill with a large black stroke.]
#[
#show: e.reset(container)
#show: e.set_(container, stroke: blue)
#container[This has no fill with a normal-sized (not 5pt) blue stroke.]
]
#container[Back to red fill with large black stroke.]