Simplify page setup examples

Fixes #2132
This commit is contained in:
Laurenz 2023-09-14 13:40:16 +02:00
parent 3dd12d13f8
commit 9036444c8c

View File

@ -174,15 +174,13 @@ conditionally remove the header on the first page:
```typ ```typ
>>> #set page("a5", margin: (x: 2.5cm, y: 3cm)) >>> #set page("a5", margin: (x: 2.5cm, y: 3cm))
#set page( #set page(header: locate(loc => {
header: locate(loc => { if counter(page).at(loc).first() > 1 [
if counter(page).at(loc).first() > 1 [ _Lisa Strassner's Thesis_
_Lisa Strassner's Thesis_ #h(1fr)
#h(1fr) National Academy of Sciences
National Academy of Sciences ]
] }))
}),
)
#lorem(150) #lorem(150)
``` ```
@ -208,22 +206,20 @@ such a label exists on the current page:
```typ ```typ
>>> #set page("a5", margin: (x: 2.5cm, y: 3cm)) >>> #set page("a5", margin: (x: 2.5cm, y: 3cm))
#set page( #set page(header: locate(loc => {
header: locate(loc => { let page-counter = counter(page)
let page-counter = counter(page) let matches = query(<big-table>, loc)
let matches = query(<big-table>, loc) let current = page-counter.at(loc)
let current = page-counter.at(loc) let has-table = matches.any(m =>
let has-table = matches.any(m => page-counter.at(m.location()) == current
page-counter.at(m.location()) == current )
)
if not has-table [ if not has-table [
_Lisa Strassner's Thesis_ _Lisa Strassner's Thesis_
#h(1fr) #h(1fr)
National Academy of Sciences National Academy of Sciences
] ]
}), }))
)
#lorem(100) #lorem(100)
#pagebreak() #pagebreak()
@ -295,100 +291,45 @@ a custom footer with page numbers and more.
```example ```example
>>> #set page("iso-b6", margin: 1.75cm) >>> #set page("iso-b6", margin: 1.75cm)
#set page( #set page(footer: [
footer: locate(loc => { *American Society of Proceedings*
let page-num = counter(page) #h(1fr)
.at(loc) #counter(page).display(
.first() "1/1",
both: true,
let page-total = counter(page) )
.final(loc) ])
.first()
strong[
American Society of Proceedings
]
h(1fr)
[#page-num/#page-total]
})
)
This page has a custom footer. This page has a custom footer.
``` ```
The example above shows how to add a custom footer with page numbers. First, we First, we add some strongly emphasized text on the left and add free space to
need to recover the page number using the page counter. For this, we are using fill the line. Then, we call `counter(page)` to retrieve the page counter and
the [`{locate}` function]($locate) to check the page counter, just like in use its `display` function to show its current value. We also set `both` to
the conditional header section. We then store the current and final page number `{true}` so that our numbering pattern applies to the current _and_ final page
in variables. number.
Then, we can proceed to build our footer. We add a strong label on the left, We can also get more creative with the page number. For example, let's insert a
insert all the free space on the line, and finally display the current page circle for each page.
number and the page total. This would work just the same in the header and with
any content.
We can, of course, use the [`{numbering}` function]($numbering) to use numbering
pattern strings like before:
```example ```example
>>> #set page("iso-b6", margin: 1.75cm) >>> #set page("iso-b6", margin: 1.75cm)
#set page( #set page(footer: [
footer: locate(loc => { *Fun Typography Club*
let page-num = counter(page) #h(1fr)
.at(loc) #counter(page).display(num => {
.first() let circles = num * (
let page-total = counter(page)
.final(loc)
.first()
strong[
American Society of Proceedings
]
h(1fr)
numbering(
"i of I",
page-num,
page-total
)
})
)
This page has a custom footer.
```
The `{numbering}` function accepts multiple arguments. It will use the arguments
in order for each number character. You could, for example, put the page total
in front of the page number by reversing the argument order.
We can even use these variables to get more creative with the page number. For
example, let's insert a circle for each page.
```example
>>> #set page("iso-b6", margin: 1.75cm)
#set page(
footer: locate(loc => {
let page-num = counter(page)
.at(loc)
.first()
let circles = (
box(circle( box(circle(
radius: 2pt, radius: 2pt,
fill: navy, fill: navy,
)), )),
) * page-num )
strong[Fun Typography Club]
h(1fr)
box( box(
inset: (bottom: 1pt), inset: (bottom: 1pt),
circles.join(h(1pt)) circles.join(h(1pt))
) )
}) })
) ])
This page has a custom footer. This page has a custom footer.
``` ```
@ -426,22 +367,22 @@ start of a page because it will otherwise create a page break. You can also
update the counter given its previous value by passing a function: update the counter given its previous value by passing a function:
```typ ```typ
#counter(page).update(i => i + 5) #counter(page).update(n => n + 5)
``` ```
In this example, we skip five pages. `i` is the current value of the page In this example, we skip five pages. `n` is the current value of the page
counter and `i + 5` is the return value of our function. counter and `n + 5` is the return value of our function.
In case you need to retrieve the actual page number instead of the value of the In case you need to retrieve the actual page number instead of the value of the
page counter, you can use the [`page`]($locate) method on the argument of the page counter, you can use the [`page`]($locate) method on the argument of the
`{locate}` closure: `{locate}` closure:
```example ```example
#counter(page).update(i => i + 5) #counter(page).update(n => n + 5)
// This returns one even though the // This returns one even though the
// page counter was incremented by 5. // page counter was incremented by 5.
#locate(loc => {loc.page()}) #locate(loc => loc.page())
``` ```
You can also obtain the page numbering pattern from the `{locate}` closure You can also obtain the page numbering pattern from the `{locate}` closure