Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/preview/presentate/0.2.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 pacaunt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
189 changes: 189 additions & 0 deletions packages/preview/presentate/0.2.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# Presentate
**Presentate** is a package for creating presentation in Typst. It provides a framework for creating dynamic animation that is compatible with other packages.
For usage, please refer to [demo.pdf](https://github.com/user-attachments/files/21795556/demo.pdf)


## Simple Usage
Import the package with
```typst
#import "@preview/presentate:0.2.0": *
```
and then, the functions are automatically available.

### Creating slides
You can create a slide using `slide` function. For simple animation, you can use `pause` function to show show some content later.
The easiest is to type `#show: pause`. For example,
```typst
#set page(paper: "presentation-16-9")
#set text(size: 25pt)

#slide[
Hello World!
#show: pause;

This is `presentate`.
]
```

which results in
<img width="1620" height="464" alt="example1" src="https://github.com/user-attachments/assets/8bc0d428-cf3f-4e49-96b2-093cbbf10e2e" />

You can style the slides as you would do with normal Typst document. For example,

```typst
#set page(paper: "presentation-16-9")
#set text(size: 25pt, font: "FiraCode Nerd Font Mono")
#set align(horizon)

#slide[
= Welcome to Presentate!
\ A lazy author \
#datetime.today().display()
]

#set align(top)

#slide[
== Tips for Typst.

#set align(horizon)
Do you know that $pi != 3.141592$?

#show: pause
Yeah. Certainly.

#show: pause
Also $pi != 22/7$.
]


```

<img width="1479" height="850" alt="example2" src="https://github.com/user-attachments/assets/c071e008-a1eb-4c59-b693-fbeea9bf70aa" />

### Relative Index Specification
You can use `none` and `auto` to specify the index as *with previous animation* or *after previous animation*.
This is useful for modifying steps of the animation so that some contents appear with or after another.
One application is for showing contents in sync:

```typst
#slide[
= Content in Sync
#table(columns: (1fr, 1fr), stroke: 1pt)[
First

#show: pause;
I am

#show: pause;

in sync.
][
// `[]` is a dummy content.
#uncover(1, [], update-pause: true)
Second

#show: pause;
I am

#show: pause;

in sync.

#show: pause
Heheh
]
]
```

<img width="1463" height="842" alt="image" src="https://github.com/user-attachments/assets/cfff30c3-eae0-4d8c-bcec-3d891368d662" />





### Package Integration

Use can use the `render` function to create a workspace, and import the `animation` module of Presentate to create animation with other packages.
For example, Integration with [CeTZ](https://typst.app/universe/package/cetz) and [Fletcher](https://typst.app/universe/package/fletcher)
```typst
#import "@preview/cetz:0.4.1": canvas, draw
#import "@preview/fletcher:0.5.8": diagram, edge, node

#slide[
= CeTZ integration
#render(s => ({
import animation: *
let (pause,) = settings(hider: draw.hide.with(bounds: true))
canvas({
import draw: *
pause(s, circle((0, 0), fill: green))
s.push(auto) // update s
pause(s, circle((1, 0), fill: red))
})
},s)
)
]

#slide[
= Fletcher integration
#render(s => ({
import animation: *
diagram($
pause(#s, A edge(->)) #s.push(auto)
& pause(#s, B edge(->)) #s.push(auto)
pause(#s, edge(->, "d") & C) \
& pause(#s, D)
$,)
}, s,))
]
```
Results:

<img width="833" height="973" alt="image" src="https://github.com/user-attachments/assets/971a4739-1c13-45f6-9699-308760dc34d9" />

You can incrementally show the content from other package by wrap the functions in the `animate` function, with a modifiers that modifies the function's arguments to hide the content using `modifier`.
For example, this molecule animation is created compatible with [Alchemist](https://typst.app/universe/package/alchemist) package:

```typst
#import "@preview/alchemist:0.1.6" as alc

#let modifier(func, ..args) = func(stroke: none, ..args) // hide the bonds with `stroke: none`
#let (single,) = animation.animate(modifier: modifier, alc.single)
#let (fragment,) = animation.animate(modifier: (func, ..args) => none, alc.fragment) // hide the molecule with `none`

#slide[
= Alchemist Molecules
#render(s => ({
alc.skeletize({
fragment(s, "H_3C")
s.push(auto)
single(s, angle: 1)
fragment(s, "CH_2")
s.push(auto)
single(s, angle: -1, from: 0)
fragment(s, "CH_2")
s.push(auto)
single(s, from: 0, angle: 1)
fragment(s, "CH_3")
})
},s)
)
]
```

which results in

<img width="1008" height="879" alt="image" src="https://github.com/user-attachments/assets/e6e04579-e4a0-464e-b4b7-4189ad162d5d" />


## Versions
### 0.2.0
- Change the framework of animations, using one state for all cover functions.
- Introduce `render` and `animation` for more flexible package integration.
### 0.1.0
Initial Release

## Acknowledgement
Thanks [Minideck package author](https://github.com/knuesel/typst-minideck) for the `minideck` package that inspires me the syntax and examples.
[Touying package authors](https://github.com/touying-typ/touying) and [Polylux author](https://github.com/polylux-typ/polylux) for inspring me the syntax and parsing method.
145 changes: 145 additions & 0 deletions packages/preview/presentate/0.2.0/src/animation.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#import "utils.typ"
#import "store.typ"
#import "indices.typ"

// show only when the number of pauses are less than or equal to the subslide number.
#let pause(s, body, hider: it => none) = {
let (info, ..idx) = s
let (pauses,) = indices.resolve-indices(s)
if pauses <= info.subslide or info.handout {
body
} else { hider(body) }
}


#let uncover(s, ..n, body, hider: hide, from: (), to: ()) = {
let (info, ..x) = s
let (pauses, results: (..n)) = indices.resolve-indices(s, ..n)

// Show only when the subslides are in the specified indices, or in the range of from-to.
// Minideck's original
let logic(i) = {
if i in n { return true }
let tmp = ()
if from != () { tmp.push(from) } else if to != () {
panic("`from` must be specified in order to use `to`.")
}
if to != () { tmp.push(to) }

let (results: tmp) = indices.resolve-indices(s, ..tmp)

if tmp.len() == 1 {
let (from,) = tmp
return i >= from
} else if tmp.len() == 2 {
let (from, to) = tmp
return from <= i and i <= to
} else {
false
}
}
if logic(info.subslide) or info.handout {
body
} else { hider(body) }
}

#let only(s, ..n, body, hider: it => none, from: (), to: ()) = {
uncover(s, ..n, body, hider: hider, from: from, to: to)
}



#let fragments(
s,
start: auto,
..bodies,
hider: it => none,
reveal-step: false,
repeat-last: true,
item-wrapper: it => it,
) = {
let (info, ..x) = s
let (results: (start,)) = indices.resolve-indices(s, start)
bodies = bodies.pos().map(item-wrapper)
let last-index = if not repeat-last { start + bodies.len() - 1 } else { () }

// Very similar idea to Polylux's one-by-one and friends.
for (i, v) in bodies.enumerate() {
if reveal-step {
uncover(s, start + i, v, hider: hider)
} else {
uncover(s, from: start + i, to: last-index, v, hider: hider)
}
}
}

#let transform(
s,
start: auto,
body,
..funcs,
before-func: it => none,
repeat-last: true,
hider: it => none,
) = {
let (info, ..x) = s
let (results: (start,)) = indices.resolve-indices(s, start)
funcs = funcs
.pos()
.map(f => {
if type(f) != function { x => f } else { f }
})
let last-index = start + funcs.len()

if info.subslide < start {
before-func(body)
} else if info.subslide < last-index {
(funcs.at(info.subslide - start))(body)
} else {
if repeat-last { (funcs.last())(body) } else { hider(body) }
}
}

#let alert(s, ..n, from: auto, to: (), body, func: emph) = {
uncover(s, ..n, func(body), hider: it => body, from: from, to: to)
}

// Modify the function so that it can react to the state variable `s`
// Default behaviour is like `pause`
#let animate(
..funcs,
wrapper: pause,
hider: it => none,
modifier: none, // if it is not `none` then it must be `(func, ..args) => ..`
) = {
funcs
.pos()
.map(func => (s, ..args) => wrapper(
s,
hider: {
if modifier != none {
// modifier will replace `hider` if it is specified.
it => modifier(func, ..args)
} else { hider }
},
func(..args),
))
}

#let settings(hider: it => none, start: auto) = {
(
pause: pause.with(hider: hider),
uncover: uncover.with(hider: hider),
fragments: fragments.with(start: start, hider: hider),
transform: transform.with(hider: hider, start: start),
)
}

// Touying and Polylux's Idea.
#let pdfpc-slide-markers(i) = context [
#metadata((t: "NewSlide")) <pdfpc>
#metadata((t: "Idx", v: here().page())) <pdfpc>
#metadata((t: "Overlay", v: i - 1)) <pdfpc>
#metadata((t: "LogicalSlide", v: counter(page).get().first())) <pdfpc>
]

8 changes: 8 additions & 0 deletions packages/preview/presentate/0.2.0/src/export.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import "presentate.typ": slide
#import "animation.typ"
#import "indices.typ"
#import "render.typ": pause, only, uncover, fragments, transform, render, alert
#import "utils.typ"
#import "store.typ" as store: set-options
#import "themes/themes.typ"

16 changes: 16 additions & 0 deletions packages/preview/presentate/0.2.0/src/freeze_counters.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import "utils.typ"
#import "store.typ": prefix, states

/// freeze the states by update the location back to the start location of the slide.
/// Same logic with Touying.

#let start-location = state(prefix + "_start_location")

#let freeze-states-mark() = {
let (info, ..x) = states.get()
let loc = start-location.get()
if info.freeze-states {
info.frozen-states-and-counters.map(c => c.update(c.at(loc))).join()
}
}

Loading