Skip to content

Commit

Permalink
Implement reveal-code and remove list-one-by-one etc
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasKroepelin committed Jan 19, 2025
1 parent 7f20973 commit 6e90644
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
58 changes: 25 additions & 33 deletions logic.typ
Original file line number Diff line number Diff line change
Expand Up @@ -204,39 +204,31 @@
alternatives-match(cases.zip(contents), ..kwargs.named())
}

#let _items-one-by-one(fn, start: 1, mode: "invisible", ..args) = {
let kwargs = args.named()
let items = args.pos()
let covered-items = items.enumerate().map(
((idx, item)) => uncover((beginning: idx + start), mode: mode, item)
)
fn(
..kwargs,
..covered-items
)
}

#let list-one-by-one(start: 1, mode: "invisible", ..args) = {
_items-one-by-one(list, start: start, mode: mode, ..args)
}

#let enum-one-by-one(start: 1, mode: "invisible", ..args) = {
_items-one-by-one(enum, start: start, mode: mode, ..args)
}

#let terms-one-by-one(start: 1, mode: "invisible", ..args) = {
let kwargs = args.named()
let items = args.pos()
let covered-items = items.enumerate().map(
((idx, item)) => terms.item(
item.term,
uncover((beginning: idx + start), mode: mode, item.description)
)
)
terms(
..kwargs,
..covered-items
)
#let reveal-code(start: 1, lines: (), before: gray, after: hide, body) = {
lines.insert(0, 0)
// lines.push(1000000)
let (before-action, after-action) = (before, after).map(c => {
if type(c) == color {
it => text(fill: c, it.text)
} else if c == hide {
hide
} else {
panic("Illegal mode: " + str(c))
}
})
for (idx, (from , to)) in lines.windows(2).enumerate() {
show raw.line: it => {
if it.number <= from {
before-action(it)
} else if it.number > to {
after-action(it)
} else {
it
}
}
only(start + idx, body)
}
only((beginning: start + lines.len()), body)
}

#let later(body, strand: 1) = {
Expand Down
2 changes: 1 addition & 1 deletion polylux.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// #import "themes/themes.typ"
#import "logic.typ"
#import "logic.typ": slide, uncover, only, alternatives, alternatives-match, alternatives-fn, alternatives-cases, one-by-one, item-by-item, list-one-by-one, enum-one-by-one, terms-one-by-one, later, enable-handout-mode
#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
#import "utils/utils.typ"
#import "utils/utils.typ": polylux-outline, big, side-by-side, pdfpc, last-slide-number, slide-number
15 changes: 15 additions & 0 deletions tests/reveal-code.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import "../polylux.typ": *

#set page(paper: "presentation-16-9")

#slide[
#reveal-code(lines: (3, 4, 6), before: silver)[```julia
function foo(x)
@show x
s = sum(x) do xi
xi ^ 2 + 3
end
x ./ s
end
```]
]

0 comments on commit 6e90644

Please sign in to comment.