animate
animate(body, effects: (), alignment: top + left)(source)Animate content arbitrarily with your own or builtin effects. Use this for special cases where you want to combine visibility, effects, ... Effects may be layered arbitrarily.
Example:
#animate(
[The original],
effects: (
(effect: "cover", subslides: "-2"),
(effect: swap[Something else], subslides: 3),
(effect: (body, ..) => text(red, body), subslides: "4-", priority: 2),
),
)
Placement versus styling
Effects fall into two classes, and they combine differently.
Placements — "show", "cover", "remove" and swap(..) — decide
whether and in what form body appears at all. Exactly one of them applies
per subslide, see priority below.
Styles — any function you pass — all apply, nested inside one another, because that is something Typst composes correctly on its own.
Priority
An effect of type "show" with subslides "1-" and priority 0 is
applied by default, and your own effects default to priority 1, so
writing any placement at all replaces it. Among the placements active on a
subslide the highest priority wins, ties going to the last one written. For
styles priority only sets the nesting order: lowest is innermost, and
within one priority the last one written is innermost, so it wins any
property both of them set.
Ties therefore break the same way in both classes — the last effect you wrote wins — a placement by being the one used, a style by ending up innermost.
animate-hidden and animate-removed are this function with a "cover"
or "remove" placement already in front of your effects at priority 0, so
anything you write still takes precedence over it.
Space
"cover" reserves body's space entirely and "remove" reserves none at
all, exactly as uncover and only do. A swap replaces body outright,
just like alternatives, and reflows the layout while it is shown —
unless it is given stretch: true, which puts it into the reserved space
along with body itself, so that the block keeps one size throughout.
Nothing is measured unless at least one swap asks to stretch. When one
does, the reserved space is the overlay of everything that actually renders
and reserves, measured with the styles that are active where it renders:
each distinct combination of placement and styles is measured once. As with
alternatives' stretch, zero-length content such as a bare context
expression cannot be measured usefully, provide a fixed-size box wrapping
it in that case.
body : content
The entire content onto which the effects will apply.
effects : array | dictionary default: ()
The effects, each a dictionary with the keys below. A single effect may be given on its own instead of in an array.
- effect (function, str, dictionary): The builtin effects are
"cover","remove","show"andswap(body, alignment: top + left, stretch: false). If passed a function it needs the following header:(body, self: none) -> content
From self you can extract the current subslide and waypoint. To use a simple function liketext.with(red)write(body, ..args) => text(red, body)instead. - subslides (int, str, label, dictionary): Subslide types as usual (see docstring of
uncover), corresponding to integer subslides, string subslide ranges, waypoints or waypoint markers. The effect will only be invoked if the current subslide is among the range given. Defaults to"1-". - priority (int): Defaults to
1. See above.
If you want to cover content via utils.alpha-changing-cover or
utils.color-changing-cover, you can use those functions directly as a
styling effect.
alignment : alignment default: top + left
Where body itself sits inside the reserved box,
when a swap makes one necessary. Each swap carries its own alignment.
Returns: content