-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
- 通过自定义状态制作页眉这一小结,我总是不能成功浮现,实在是让人苦恼
- 能否再详细一点,或者能点评以下我的代码哪里有误?
#let first-heading = state("first-heading", ())
#let last-heading = state("last-heading", ())
#show heading.where(level: 2): curr-heading => {
curr-heading //返回值不变
context first-heading.update(headings => {
//字典没有这个键才插入一次,有的话就不插入了,所以得到第一个
let page = str(here().page())
if page not in headings {
headings.insert(page, curr-heading.body)
}
headings //返回更新值
})
context last-heading.update(headings => {
//字典特性,比如在第三页持续覆盖旧值
headings.insert(str(here().page()), curr-heading.body)
headings
})
}
#let get-heading-at-page() = context {
let find-headings(headings, page) = if page > 0 {
headings.at(str(page), default: find-headings(headings, page - 1))
}
let first-headings = first-heading.final(here())
let last-headings = last-heading.get()
let page = here().page()
first-headings.at(str(page), default: find-headings(last-headings, page))
}
#set page(header: emph(get-heading-at-page()))YDX-2147483647
Metadata
Metadata
Assignees
Labels
No labels