feat: initial commit
This commit is contained in:
commit
b802ff49ab
454 files changed
+52429
No files matched your search
@@ -0,0 +1,94 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
---
|
||||
|
||||
# Complex Animations
|
||||
|
||||
Thanks to the syntax provided by [Polylux](https://polylux.dev/book/dynamic/syntax.html), we can also use `only`, `uncover`, and `alternatives` in Touying.
|
||||
|
||||
|
||||
## Mark-Style Functions
|
||||
|
||||
We can use mark-style functions, which are very convenient to use.
|
||||
|
||||
```typst
|
||||
At subslide #touying-fn-wrapper((self: none) => str(self.subslide)), we can
|
||||
|
||||
use #uncover("2-")[`#uncover` function] for reserving space,
|
||||
|
||||
use #only("2-")[`#only` function] for not reserving space,
|
||||
|
||||
#alternatives[call `#only` multiple times \u{2717}][use `#alternatives` function #sym.checkmark] for choosing one of the alternatives.
|
||||
```
|
||||
|
||||
However, this does not work in all cases, for example if you put `uncover` into the context expression, you will get an error.
|
||||
|
||||
|
||||
## Callback-Style Functions
|
||||
|
||||
To overcome the limitations of layout functions mentioned earlier, Touying cleverly implements always-effective `only`, `uncover`, and `alternatives` using callback functions. Specifically, you need to introduce these three functions as follows:
|
||||
|
||||
```typst
|
||||
#slide(repeat: 3, self => [
|
||||
#let (uncover, only, alternatives) = utils.methods(self)
|
||||
|
||||
At subslide #self.subslide, we can
|
||||
|
||||
use #uncover("2-")[`#uncover` function] for reserving space,
|
||||
|
||||
use #only("2-")[`#only` function] for not reserving space,
|
||||
|
||||
#alternatives[call `#only` multiple times \u{2717}][use `#alternatives` function #sym.checkmark] for choosing one of the alternatives.
|
||||
])
|
||||
```
|
||||
|
||||

|
||||
|
||||
Notice that we no longer pass a content block but instead pass a callback function with a `self` parameter. Later, we extract `only`, `uncover`, and `alternatives` functions from `self` using:
|
||||
|
||||
```typst
|
||||
#let (uncover, only, alternatives) = utils.methods(self)
|
||||
```
|
||||
|
||||
We then call these functions in subsequent steps.
|
||||
|
||||
Here's an interesting fact: the `self.subslide` of type int indicates the current subslide index, and in fact, the `only`, `uncover`, and `alternatives` functions rely on `self.subslide` to determine the current subslide index.
|
||||
|
||||
:::warning[Warning]
|
||||
|
||||
We manually specify the `repeat: 3` parameter, indicating the display of 3 subslides. We need to do this manually because Touying cannot infer how many subslides `only`, `uncover`, and `alternatives` should display.
|
||||
|
||||
:::
|
||||
|
||||
## only
|
||||
|
||||
The `only` function means it "appears" only on selected subslides. If it doesn't appear, it completely disappears and doesn't occupy any space. In other words, `#only(index, body)` is either `body` or `none`.
|
||||
|
||||
The index can be an int type or a str type like `"2-"` or `"2-3"`. For more usage, refer to [Polylux](https://polylux.dev/book/dynamic/complex.html).
|
||||
|
||||
## uncover
|
||||
|
||||
The `uncover` function means it "displays" only on selected subslides; otherwise, it will be covered by the `cover` function but still occupies the original space. In other words, `#uncover(index, body)` is either `body` or `cover(body)`.
|
||||
|
||||
The index can be an int type or a str type like `"2-"` or `"2-3"`. For more usage, refer to [Polylux](https://polylux.dev/book/dynamic/complex.html).
|
||||
|
||||
You may also have noticed that `#pause` actually uses the `cover` function, providing a more convenient syntax. In reality, their effects are almost identical.
|
||||
|
||||
## alternatives
|
||||
|
||||
The `alternatives` function displays a series of different content in different subslides. For example:
|
||||
|
||||
```typst
|
||||
#slide(repeat: 3, self => [
|
||||
#let (uncover, only, alternatives) = utils.methods(self)
|
||||
|
||||
#alternatives[Ann][Bob][Christopher]
|
||||
likes
|
||||
#alternatives[chocolate][strawberry][vanilla]
|
||||
ice cream.
|
||||
])
|
||||
```
|
||||
|
||||

|
||||
|
||||
As you can see, `alternatives` can automatically expand to the most suitable width and height, a capability that `only` and `uncover` lack. In fact, `alternatives` has other parameters, such as `start: 2`, `repeat-last: true`, and `position: center + horizon`. For more usage, refer to [Polylux](https://polylux.dev/book/dynamic/alternatives.html).
|
||||
@@ -0,0 +1,66 @@
|
||||
---
|
||||
sidebar_position: 4
|
||||
---
|
||||
|
||||
# Cover Function
|
||||
|
||||
As you already know, both `uncover` and `#pause` use the `cover` function to conceal content that is not visible. So, what exactly is the `cover` function here?
|
||||
|
||||
## Default Cover Function: `hide`
|
||||
|
||||
The `cover` function is a method stored in `s.methods.cover`, which is later used by `uncover` and `#pause`.
|
||||
|
||||
The default `cover` function is the [hide](https://typst.app/docs/reference/layout/hide/) function. This function makes the internal content invisible without affecting the layout.
|
||||
|
||||
## Updating the Cover Function
|
||||
|
||||
In some cases, you might want to use your own `cover` function. In that case, you can set your own `cover` function using:
|
||||
|
||||
```typst
|
||||
config-methods(cover: (self: none, body) => hide(body))
|
||||
```
|
||||
|
||||
## hack: handle enum and list
|
||||
|
||||
You will find that the existing cover function cannot hide the mark of enum and list, refer to [here](https://github.com/touying-typ/touying/issues/10), so you can hack:
|
||||
|
||||
```typst
|
||||
config-methods(cover: (self: none, body) => box(scale(x: 0%, body)))
|
||||
```
|
||||
|
||||
## Semi-Transparent Cover Function
|
||||
|
||||
Touying supports a semi-transparent cover function, which can be enabled by adding:
|
||||
|
||||
```typst
|
||||
config-methods(cover: utils.semi-transparent-cover.with(alpha: 85%))
|
||||
```
|
||||
|
||||
You can adjust the transparency through the `alpha: ..` parameter.
|
||||
|
||||
:::warning[Warning]
|
||||
|
||||
Note that the `transparent-cover` here does not preserve text layout like `hide` does because it adds an extra layer of `box`, which may disrupt the original structure of the page.
|
||||
|
||||
:::
|
||||
|
||||
:::tip[Internals]
|
||||
|
||||
The `utils.semi-transparent-cover` method is defined as:
|
||||
|
||||
```typst
|
||||
#let semi-transparent-cover(self: none, constructor: rgb, alpha: 85%, body) = {
|
||||
cover-with-rect(
|
||||
fill: update-alpha(
|
||||
constructor: constructor,
|
||||
self.page.fill,
|
||||
alpha,
|
||||
),
|
||||
body,
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
It creates a semi-transparent rectangular mask with the same color as the background to simulate the effect of transparent content. Here, `constructor: rgb` and `alpha: 85%` indicate the background color's construction function and transparency level, respectively.
|
||||
|
||||
:::
|
||||
@@ -0,0 +1,49 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
---
|
||||
|
||||
# Math Equation Animations
|
||||
|
||||
Touying also provides a unique and highly useful feature—math equation animations, allowing you to conveniently use `pause` and `meanwhile` within math equations.
|
||||
|
||||
## Simple Animation
|
||||
|
||||
Let's start with an example:
|
||||
|
||||
```typst
|
||||
#slide[
|
||||
Touying equation with pause:
|
||||
|
||||
$
|
||||
f(x) &= pause x^2 + 2x + 1 \
|
||||
&= pause (x + 1)^2 \
|
||||
$
|
||||
|
||||
#meanwhile
|
||||
|
||||
Touying equation is very simple.
|
||||
]
|
||||
```
|
||||
|
||||

|
||||
|
||||
We use the `touying-equation` function to incorporate `pause` and `meanwhile` within the text of math equations (in fact, you can also use `#pause` or `#pause;`).
|
||||
|
||||
As you would expect, the math equation is displayed step by step, making it suitable for presenters to demonstrate their math reasoning.
|
||||
|
||||
## Complex Animation
|
||||
|
||||
In fact, we can also use `only`, `uncover`, and `alternatives`:
|
||||
|
||||
```typst
|
||||
#slide(repeat: 3, self => [
|
||||
#let (uncover, only, alternatives) = utils.methods(self)
|
||||
|
||||
$
|
||||
f(x) &= pause x^2 + 2x + uncover("3-", 1) \
|
||||
&= pause (x + 1)^2 \
|
||||
$
|
||||
])
|
||||
```
|
||||
|
||||

|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
sidebar_position: 6
|
||||
---
|
||||
|
||||
# Handout Mode
|
||||
|
||||
While watching slides and attending lectures, the audience often wishes to have handouts for reviewing challenging concepts. Therefore, it's beneficial for the author to provide handouts for the audience, preferably before the lecture for better preparation.
|
||||
|
||||
The handout mode differs from the regular mode as it doesn't require intricate animation effects. It retains only the last subslide of each slide.
|
||||
|
||||
Enabling handout mode is simple:
|
||||
|
||||
```typst
|
||||
config-common(handout: true)
|
||||
```
|
||||
@@ -0,0 +1,100 @@
|
||||
---
|
||||
sidebar_position: 5
|
||||
---
|
||||
|
||||
# Other Animations
|
||||
|
||||
Touying also provides `touying-reducer`, which adds `pause` and `meanwhile` animations to cetz and fletcher.
|
||||
|
||||
## Simple Animations
|
||||
|
||||
Here's an example:
|
||||
|
||||
```typst
|
||||
#import "@preview/touying:0.6.1": *
|
||||
#import themes.university: *
|
||||
#import "@preview/cetz:0.3.2"
|
||||
#import "@preview/fletcher:0.5.5" as fletcher: node, edge
|
||||
|
||||
// cetz and fletcher bindings for touying
|
||||
#let cetz-canvas = touying-reducer.with(reduce: cetz.canvas, cover: cetz.draw.hide.with(bounds: true))
|
||||
#let fletcher-diagram = touying-reducer.with(reduce: fletcher.diagram, cover: fletcher.hide)
|
||||
|
||||
#show: university-theme.with(aspect-ratio: "16-9")
|
||||
|
||||
// cetz animation
|
||||
#slide[
|
||||
Cetz in Touying:
|
||||
|
||||
#cetz-canvas({
|
||||
import cetz.draw: *
|
||||
|
||||
rect((0,0), (5,5))
|
||||
|
||||
(pause,)
|
||||
|
||||
rect((0,0), (1,1))
|
||||
rect((1,1), (2,2))
|
||||
rect((2,2), (3,3))
|
||||
|
||||
(pause,)
|
||||
|
||||
line((0,0), (2.5, 2.5), name: "line")
|
||||
})
|
||||
]
|
||||
|
||||
// fletcher animation
|
||||
#slide[
|
||||
Fletcher in Touying:
|
||||
|
||||
#fletcher-diagram(
|
||||
node-stroke: .1em,
|
||||
node-fill: gradient.radial(blue.lighten(80%), blue, center: (30%, 20%), radius: 80%),
|
||||
spacing: 4em,
|
||||
edge((-1,0), "r", "-|>", `open(path)`, label-pos: 0, label-side: center),
|
||||
node((0,0), `reading`, radius: 2em),
|
||||
edge((0,0), (0,0), `read()`, "--|>", bend: 130deg),
|
||||
pause,
|
||||
edge(`read()`, "-|>"),
|
||||
node((1,0), `eof`, radius: 2em),
|
||||
pause,
|
||||
edge(`close()`, "-|>"),
|
||||
node((2,0), `closed`, radius: 2em, extrude: (-2.5, 0)),
|
||||
edge((0,0), (2,0), `close()`, "-|>", bend: -40deg),
|
||||
)
|
||||
]
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
## only and uncover
|
||||
|
||||
In fact, we can also use `only` and `uncover` within cetz, just requiring a bit of skill:
|
||||
|
||||
```typst
|
||||
#slide(repeat: 3, self => [
|
||||
#let (uncover, only) = utils.methods(self)
|
||||
|
||||
Cetz in Touying in subslide #self.subslide:
|
||||
|
||||
#cetz.canvas({
|
||||
import cetz.draw: *
|
||||
let self = utils.merge-dicts(
|
||||
self,
|
||||
config-methods(cover: utils.method-wrapper(hide.with(bounds: true))),
|
||||
)
|
||||
let (uncover,) = utils.methods(self)
|
||||
|
||||
rect((0,0), (5,5))
|
||||
|
||||
uncover("2-3", {
|
||||
rect((0,0), (1,1))
|
||||
rect((1,1), (2,2))
|
||||
rect((2,2), (3,3))
|
||||
})
|
||||
|
||||
only(3, line((0,0), (2.5, 2.5), name: "line"))
|
||||
})
|
||||
])
|
||||
```
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
---
|
||||
|
||||
# Simple Animations
|
||||
|
||||
Touying provides two markers for simple animation effects: `#pause` and `#meanwhile`.
|
||||
|
||||
## pause
|
||||
|
||||
The purpose of `#pause` is straightforward – it separates the subsequent content into the next subslide. You can use multiple `#pause` to create multiple subslides. Here's a simple example:
|
||||
|
||||
```typst
|
||||
#slide[
|
||||
First #pause Second
|
||||
|
||||
#pause
|
||||
|
||||
Third
|
||||
]
|
||||
```
|
||||
|
||||

|
||||
|
||||
This example will create three subslides, gradually revealing the content.
|
||||
|
||||
As you can see, `#pause` can be used inline or on a separate line.
|
||||
|
||||
## meanwhile
|
||||
|
||||
In some cases, you may need to display additional content simultaneously with `#pause`. In such cases, you can use `#meanwhile`.
|
||||
|
||||
```typst
|
||||
#slide[
|
||||
First
|
||||
|
||||
#pause
|
||||
|
||||
Second
|
||||
|
||||
#meanwhile
|
||||
|
||||
Third
|
||||
|
||||
#pause
|
||||
|
||||
Fourth
|
||||
]
|
||||
```
|
||||
|
||||

|
||||
|
||||
This example will create only two subslides, with "First" and "Third" displayed simultaneously, and "Second" and "Fourth" displayed simultaneously.
|
||||
Reference in new issue
Block a user