Skip to content
Open
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
19 changes: 19 additions & 0 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
pull_request:

jobs:
check-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Typstyle
run: |
mkdir -p "$HOME/.local/bin"
wget "https://github.com/typstyle-rs/typstyle/releases/latest/download/typstyle-x86_64-unknown-linux-gnu" -O "$HOME/.local/bin/typstyle"
chmod +x "$HOME/.local/bin/typstyle"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Format typst files
run: typstyle --inplace src examples tests
- uses: getsentry/action-git-diff-suggestions@main
with:
message: "Typstyle suggested changes"
4 changes: 2 additions & 2 deletions book/src/toolbox/progress.typ
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
toolbox.progress-ratio(ratio => {
stack(
dir: ltr,
rect(stroke: blue, fill: blue, width: ratio * 8cm),
rect(stroke: blue, fill: none, width: (1 - ratio) * 8cm),
rect(stroke: blue, fill: blue, width: 8cm * ratio),
rect(stroke: blue, fill: none, width: 8cm * (1 - ratio)),
)
})
}
Expand Down
42 changes: 22 additions & 20 deletions examples/demo.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "../src/polylux.typ": *
#import "../src/polylux.typ": *

#show link: set text(blue)
#set text(font: "Andika", size: 20pt)
Expand Down Expand Up @@ -26,7 +26,7 @@
// #box(image("../assets/polylux-logo.svg", height: 2em))
#h(1fr)
Polylux demo | #toolbox.current-section
]
],
)

#show heading: set block(below: 2em)
Expand Down Expand Up @@ -122,7 +122,7 @@

#slide[
= Fine-grained control
 When `#show: later` does not suffice, you can use more advanced commands to
When `#show: later` does not suffice, you can use more advanced commands to
show or hide content.

These are some of your options:
Expand All @@ -140,7 +140,7 @@
inset: .5em,
fill: aqua.lighten(80%),
radius: .5em,
text(size: .8em, body)
text(size: .8em, body),
)

#slide[
Expand Down Expand Up @@ -183,9 +183,9 @@

#slide[
= Convenient rules as strings
As as short hand option, you can also specify rules as strings in a special
syntax.
Comma separated, you can use rules of the form
As as short hand option, you can also specify rules as strings in a special
syntax.
Comma separated, you can use rules of the form
#table(
columns: (auto, auto),
column-gutter: 1em,
Expand All @@ -200,7 +200,9 @@ Comma separated, you can use rules of the form
```typ
#uncover("-2, 4-6, 8-")[Visible on subslides 1, 2, 4, 5, 6, and from 8 onwards]
```
#uncover("-2, 4-6, 8-")[Visible on subslides 1, 2, 4, 5, 6, and from 8 onwards]
#uncover(
"-2, 4-6, 8-",
)[Visible on subslides 1, 2, 4, 5, 6, and from 8 onwards]
]
]

Expand All @@ -214,24 +216,24 @@ Comma separated, you can use rules of the form

Again, you can use complex string rules, if you want.
#example[
```typ
#only("2-4, 6")[Visible on subslides 2, 3, 4, and 6]
```
#only("2-4, 6")[Visible on subslides 2, 3, 4, and 6]
```typ
#only("2-4, 6")[Visible on subslides 2, 3, 4, and 6]
```
#only("2-4, 6")[Visible on subslides 2, 3, 4, and 6]
]
]

#slide[
= `#alternatives`: Substituting content
You might be tempted to try
#example[
```typ
#only(1)[Ann] #only(2)[Bob] #only(3)[Christopher] likes #only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla] ice cream.
```
#only(1)[Ann] #only(2)[Bob] #only(3)[Christopher]
likes
#only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla]
ice cream.
```typ
#only(1)[Ann] #only(2)[Bob] #only(3)[Christopher] likes #only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla] ice cream.
```
#only(1)[Ann] #only(2)[Bob] #only(3)[Christopher]
likes
#only(1)[chocolate] #only(2)[strawberry] #only(3)[vanilla]
ice cream.
]

But it is hard to see what piece of text actually changes because everything
Expand Down Expand Up @@ -287,7 +289,7 @@ Comma separated, you can use rules of the form
- first
- second
- third
]
],
)
]

Expand Down
36 changes: 23 additions & 13 deletions src/logic.typ
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
if match-until != none {
let parsed = int(match-until.captures.first())
// assert(parsed > 0, "parsed idx is non-positive")
( until: parsed )
(until: parsed)
} else if match-beginning != none {
let parsed = int(match-beginning.captures.first())
// assert(parsed > 0, "parsed idx is non-positive")
( beginning: parsed )
(beginning: parsed)
} else if match-range != none {
let parsed-first = int(match-range.captures.first())
let parsed-last = int(match-range.captures.last())
// assert(parsed-first > 0, "parsed idx is non-positive")
// assert(parsed-last > 0, "parsed idx is non-positive")
( beginning: parsed-first, until: parsed-last )
(beginning: parsed-first, until: parsed-last)
} else if match-single != none {
let parsed = int(match-single.captures.first())
// assert(parsed > 0, "parsed idx is non-positive")
Expand Down Expand Up @@ -71,7 +71,9 @@

lower-okay and upper-okay
} else {
panic("you may only provide a single integer, an array of integers, or a string")
panic(
"you may only provide a single integer, an array of integers, or a string",
)
}
}

Expand All @@ -93,12 +95,14 @@
}
last
} else {
panic("you may only provide a single integer, an array of integers, or a string")
panic(
"you may only provide a single integer, an array of integers, or a string",
)
}
}

#let _conditional-display(visible-subslides, reserve-space, mode, body) = {
context{
context {
let vs = if reserve-space and handout-mode.at(here()) {
(:)
} else {
Expand Down Expand Up @@ -128,8 +132,14 @@
}

#let item-by-item(start: 1, mode: hide, body) = {
let is-item(it) = type(it) == content and it.func() in (
list.item, enum.item, terms.item
let is-item(it) = (
type(it) == content
and it.func()
in (
list.item,
enum.item,
terms.item,
)
)
let children = if type(body) == content and body.has("children") {
body.children
Expand All @@ -148,15 +158,15 @@

let subslides = subslides-contents.map(it => it.first())
let contents = subslides-contents.map(it => it.last())
context{
context {
let sizes = contents.map(c => measure(c))
let max-width = calc.max(..sizes.map(sz => sz.width))
let max-height = calc.max(..sizes.map(sz => sz.height))
for (subslides, content) in subslides-contents {
only(subslides, box(
width: max-width,
height: max-height,
align(position, content)
align(position, content),
))
}
}
Expand All @@ -165,7 +175,7 @@
#let alternatives(
start: 1,
repeat-last: false,
..args
..args,
) = {
let contents = args.pos()
let kwargs = args.named()
Expand All @@ -181,7 +191,7 @@
end: none,
count: none,
..kwargs,
fn
fn,
) = {
let end = if end == none {
if count == none {
Expand Down Expand Up @@ -222,7 +232,7 @@
panic("Illegal mode: " + str(c))
}
})
for (idx, (from , to)) in lines.windows(2).enumerate() {
for (idx, (from, to)) in lines.windows(2).enumerate() {
show raw.line: it => {
if it.number <= from {
before-action(it)
Expand Down
15 changes: 3 additions & 12 deletions src/polylux.typ
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#import "logic.typ": (
slide,
uncover,
only,
alternatives,
alternatives-match,
alternatives-fn,
alternatives-cases,
one-by-one,
item-by-item,
reveal-code,
later,
enable-handout-mode
alternatives, alternatives-cases, alternatives-fn, alternatives-match,
enable-handout-mode, item-by-item, later, one-by-one, only, reveal-code,
slide, uncover,
)
#import "toolbox/toolbox.typ"
21 changes: 12 additions & 9 deletions src/toolbox/pdfpc.typ
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
} else if type(time) == "string" {
time
} else {
panic(msg-name + " must be either a datetime or a string in the HH:MM format.")
panic(
msg-name
+ " must be either a datetime or a string in the HH:MM format.",
)
}

[ #metadata((t: tag-name, v: time)) <pdfpc> ]
Expand Down Expand Up @@ -79,14 +82,14 @@

let transition-str = (
default-transition.at("type", default: "replace")
+ ":" +
str(default-transition.at("duration-seconds", default: 1))
+ ":" +
dir-to-angle(default-transition.at("angle", default: rtl))
+ ":" +
default-transition.at("alignment", default: "horizontal")
+ ":" +
default-transition.at("direction", default: "outward")
+ ":"
+ str(default-transition.at("duration-seconds", default: 1))
+ ":"
+ dir-to-angle(default-transition.at("angle", default: rtl))
+ ":"
+ default-transition.at("alignment", default: "horizontal")
+ ":"
+ default-transition.at("direction", default: "outward")
)

[ #metadata((t: "DefaultTransition", v: transition-str)) <pdfpc> ]
Expand Down
5 changes: 2 additions & 3 deletions src/toolbox/toolbox-impl.typ
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@

#let progress-ratio(ratio-to-content) = context {
let ratio = (
logic.logical-slide.get().first() /
logic.logical-slide.final().first()
logic.logical-slide.get().first() / logic.logical-slide.final().first()
)
ratio-to-content(ratio)
}
Expand All @@ -61,7 +60,7 @@

#let side-by-side(columns: none, gutter: 1em, ..bodies) = {
let bodies = bodies.pos()
let columns = if columns == none { (1fr,) * bodies.len() } else { columns }
let columns = if columns == none { (1fr,) * bodies.len() } else { columns }
if columns.len() != bodies.len() {
panic("number of columns must match number of content arguments")
}
Expand Down
12 changes: 2 additions & 10 deletions src/toolbox/toolbox.typ
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#import "toolbox-impl.typ": (
pdfpc,
register-section,
current-section,
all-sections,
progress-ratio,
all-sections, big, current-section, full-width-block, last-slide-number,
next-heading, pdfpc, progress-ratio, register-section, side-by-side,
slide-number,
last-slide-number,
big,
side-by-side,
full-width-block,
next-heading,
)
8 changes: 4 additions & 4 deletions tests/alternatives.typ
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"-2": [beginning],
"3, 5": [main part],
"4": [short break],
"6-" : [end]
"6-": [end],
))

#uncover("1-8")[I am always here, for technical reasons.]
Expand All @@ -35,10 +35,10 @@
== Another test that `alternatives-match` works

#alternatives-match(position: center, (
(2, [beginning]),
(2, [beginning]),
((3, 5), [main part]),
(4, [short break]),
("6-" , [end])
("6-", [end]),
))

#uncover("1-8")[I am always here, for technical reasons.]
Expand All @@ -57,7 +57,7 @@
// == Test that `alternatives-fn` works

// #raw(lang: "typ", repr(range(1, 6)))

// #alternatives-fn(start: 2, count: 5, subslide => numbering("(i)", subslide))

#only(2)[abc]
Expand Down
2 changes: 1 addition & 1 deletion tests/first-slide.typ
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
#slide[
== Second slide
#lorem(10)
]
]
Loading