Repository navigation
Description
Opening this as a feature request since I haven’t found a way to achieve something similar to LaTeX’s \thispagestyle, i.e. (programmatically) setting the page layout for single pages while having normal text flow (the next page has the regular layout again, whenever it begins). It seems that currently it is only possible to set a page layout together with the full contents of the affected page(s).
My concrete use case are chapter title pages with additional logos in the margins, which required me to set header-ascent. I could maybe hack around this with absolute positioning on a chapter headline, but this does not cover other uses like different page margins or background colours on single pages.
I’m not completely sure what the best solution here looks like as I’m not familiar with what typst’s internal architecture allows. I could imaging something like set page(thisionly: true) or a locate() which does not only return content. If approached more generally, i.e. allowing to set some properties of the page without forcing a page break, this could also make e.g. section-based running heads a lot easier to understand than the current way with locate().
My original discussion post with my experiments below:
Discussed in #1082
Originally posted by fruchti May 3, 2023
I’m currently trying to modify the page style for every page with a chapter heading on it. This involves header and footer texts as well as different page margins from the rest. Basically, I’m looking for something more or less like \thispagestyle in LaTeX.
The first step, adding a page break before each chapter, is not an issue:
#show heading.where(level: 1): it => [
#pagebreak(weak: true)
#it
]However, I haven’t found a way to set page() the way I want. Things I’ve tried so far:
- Using
show/set(e.g.#show heading.where(level: 1): set page(..title_page_options)) effects a page break immediately after the heading. I assume since the page style is only set for the heading’s block, typst begins a new page to assure that the next block has the old page style again. [Update: With 0.5, this doesn’t do anything anymore] - Defining a function (used instead of
= Chapter Title) which includes a#set pagehas the same result. - I might be able to build a selector out of
before()andafter()which gets me pages with a chapter heading on them. With this, I could adjust the header/footer text like the example in the docs. Sincelocate()returns acontent, I cannot use this to adjust the margins. I also cannot adjust all values at once, since I didn’t find a way to pass a dictionary throughlocate(). - With
#show page: p => locate(loc => p)I got no output at all any more, so I didn’t try any further based on that. - I tried using
#set… iftogether withlocate()by returningcontentfromlocate()which either has or hasn’t a specific field, depending on whether I am currently on a page with a chapter heading or not. However, even withthe condition never holds and the style doesn’t get applied (it looks like the#set page(..title_page_options) if locate(loc => box(width: 1pt)).has("width")locate()isn’t even evaluated actually).
Activity
flavio20002 commentedon Jul 28, 2023
Hi, the page break happen also in last version https://typst.app/project/rPZKNPwCPtiozZHCzDmDLO.
What do you mean with [Update: With 0.5, this doesn’t do anything anymore]?
fruchti commentedon Sep 25, 2023
Interestingly, I cannot reproduce this any more. I retried it with a test document and typst 0.4, 0.5, 0.6, and current main and got the same result with each version (each heading produces an extra page with just the heading and page header on it and there’s a blank page at the end). Perhaps I was using some commit with a different bug in it when I opened this issue.
Test document:
laurmaedje commentedon Jul 15, 2024
Related: #1412, #1483
pithuene commentedon Oct 25, 2024
Hi, I just ran into the same problem with chapter title pages (in my case I want to hide the page header on them) and found a workaround that might be useful for others running into this problem.
Instead of setting different page styles on the page, you can put some logic into the initial page style definition so that it differs between pages.
In my case, I used a
context ifin theheaderwith aqueryto check if the page number of the next level 1 heading is the current page, in which case I leaveheadingempty.If you want to change individual pages, you could probably extend this by using something like a
metadataelement on those pages and querying for its existence in theset pagedefinition.Here is a complete example: