Skip to content

Commit

Permalink
feat: access subslide and repeat in footer and header (#24)
Browse files Browse the repository at this point in the history
* feat: access subslide and repeat in footer and header

* style: simplify code
  • Loading branch information
OrangeX4 authored Mar 29, 2024
1 parent 6a8785d commit 3c06ca1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
36 changes: 23 additions & 13 deletions slide.typ
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
// if it is a function, then call it with self
if type(it) == function {
// subslide index
self.subslide = index
it = it(self)
}
// parse the content
Expand Down Expand Up @@ -324,6 +323,12 @@
return (result-arr, max-repetitions)
}

#let _get-header-footer(self) = {
let header = utils.call-or-display(self, self.page-args.at("header", default: none))
let footer = utils.call-or-display(self, self.page-args.at("footer", default: none))
(header, footer)
}

// touying-slide
#let touying-slide(
self: none,
Expand Down Expand Up @@ -384,18 +389,6 @@
states._sections-step(repetitions)
}
}
// page header and footer
let header = utils.call-or-display(self, self.page-args.at("header", default: none))
let footer = utils.call-or-display(self, self.page-args.at("footer", default: none))
// for speed up, do not parse the content if repeat is none
if repeat == none {
return {
header = _update-states(1) + header
page(..(self.page-args + (header: header, footer: footer)), setting-with-pad(
page-preamble(1) + composer-with-side-by-side(..bodies)
))
}
}
// for single page slide, get the repetitions
if repeat == auto {
let (_, repetitions) = _parse-content(
Expand All @@ -406,7 +399,22 @@
)
repeat = repetitions
}
self.repeat = repeat
self.subslide = 1
let (header, footer) = _get-header-footer(self)
// page header and footer
// for speed up, do not parse the content if repeat is none
if repeat == none {
return {
header = _update-states(1) + header
page(..(self.page-args + (header: header, footer: footer)), setting-with-pad(
page-preamble(1) + composer-with-side-by-side(..bodies)
))
}
}

if self.handout {
self.subslide = repeat
let (conts, _) = _parse-content(self: self, index: repeat, ..bodies)
header = _update-states(1) + header
page(..(self.page-args + (header: header, footer: footer)), setting-with-pad(
Expand All @@ -417,6 +425,8 @@
let result = ()
let current = 1
for i in range(1, repeat + 1) {
self.subslide = i
let (header, footer) = _get-header-footer(self)
let new-header = header
let (conts, _) = _parse-content(self: self, index: i, ..bodies)
// update the counter in the first subslide
Expand Down
5 changes: 2 additions & 3 deletions utils/utils.typ
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// OOP: call it or display it
#let call-or-display(self, it) = {
if type(it) == function {
return it(self)
} else {
return it
it = it(self)
}
return [#it]
}

// OOP: empty page
Expand Down

0 comments on commit 3c06ca1

Please sign in to comment.