Skip to content

Skip headers and footers for skipped pages #2722

Open

Description

@lucifer1004

Description

With pagebreak(to: "odd") we can skip pages to reach a certain parity. However, headers and footers still show up on the inserted blank page. It would be nice if there could be an option to disable any rendering on the skipped pages.

Use Case

Sometimes we need the skipped pages to be completely blank.

Activity

  1. added
    feature request
    on Nov 20, 2023
  2. added
    layout
    on Nov 24, 2023
  3. Leedehai commented on Nov 30, 2023

    @Leedehai
    Contributor

    Is it more sensible to definitely not render any stuff on skipped pages?

    I mean, there are two states: A. still render headers/footers on skipped pages; B. complete blankness on skipped pages. The status quos is A, you propose letting users choose A or B via an option, and I propose only B. I can't think of any cases where A would be useful.

    I think it helps to prevent an unnecessary accumulation of options.

  4. PgBiel commented on Dec 7, 2023

    @PgBiel
    Contributor

    Is it more sensible to definitely not render any stuff on skipped pages?

    I mean, there are two states: A. still render headers/footers on skipped pages; B. complete blankness on skipped pages. The status quos is A, you propose letting users choose A or B via an option, and I propose only B. I can't think of any cases where A would be useful.

    I think it helps to prevent an unnecessary accumulation of options.

    I don't really agree with this; it may be a requirement to have headers and footers on all pages of your document, depending on whom you are submitting it to.

    I'd thus wager that the original idea of gating the feature behind an option would be more appropriate.

  5. Leedehai commented on Dec 7, 2023

    @Leedehai
    Contributor

    @PgBiel reasonable, I don't have a strong opinion on this one so I'll add the option in my PR #2882 :)

  6. laurmaedje commented on Dec 13, 2023

    @laurmaedje
    Member

    The requirement to not have headers on empty pages exists, but I think it is not specific to pagebreak(to: "even" | "odd"). Rather, it is from a user perspective about not having headers and footers on otherwise blank pages. It doesn't matter whether those come from to or from multiple consecutive pagebreaks. I've closed #2882 because I think we need to go back to the design stage on this.

    I'd thus propose to view the problem more from this angle: How can we let users say that marginals shouldn't be shown on empty pages?

    • There could be an option on the page function for this, although I don't have a good concise name for this
    • The option could be a more general marginal filter though that might be overkill
    • Perhaps, we could also make it achievable in the header itself via introspection although that has the problem that it loses composability with an existing header/footer/numbering
  7. laurmaedje commented on Dec 13, 2023

    @laurmaedje
    Member

    What also ties in with this is the ability to have something like "This page intentionally left blank" printed on the page.

  8. agrueneberg commented on Jan 25, 2024

    @agrueneberg

    Is there a workaround for custom headers? I experimented with metadata and state, but couldn't find a good solution.

  9. agrueneberg commented on Jan 25, 2024

    @agrueneberg

    Nevermind, I got it to work. Here's a my metadata based workaround for a document with a cover page that has new chapters starting on the right side:

    #let header(loc) = {
      let curpage = loc.page()
      let iscurpageeven = calc.even(curpage)
      // Show header unless <disable_header> is found on previous page and the
      // current page is even
      if not (query(<disable_header>, loc).filter(el => el.location().page() == curpage - 1) != () and iscurpageeven) {
        counter(page).at(loc).first()
      }
    }
    
    // Cover page
    #pagebreak()
    
    // Left page blank
    #counter(page).update(0)
    #set page(
      header: locate(loc => header(loc))
    )
    #pagebreak()
    
    = A
    #lorem(500)
    
    #metadata("disable_header") <disable_header>
    #pagebreak(to: "odd")
    
    = B
    #lorem(1000)
    
    #metadata("disable_header") <disable_header>
    #pagebreak(to: "odd")
    
    = C
    #lorem(500)
  10. tingerrr commented on Apr 18, 2024

    @tingerrr
    Contributor
    • There could be an option on the page function for this, although I don't have a good concise name for this
    • The option could be a more general marginal filter though that might be overkill
    • Perhaps, we could also make it achievable in the header itself via introspection although that has the problem that it loses composability with an existing header/footer/numbering

    What about creating a page.empty sub-element which inherits all styles from page by virtue of them being auto.

    Such an element could be created when pagebreak(to: _) creates intentional empty pages. As well as when a user explicitly inserts it or multiple strong pagebreaks.

    Then, simple show/set rules would allow us to set heading and footer to none, or setting the default content using the background/foreground.

    #set page.empty(
      header: none,
      footer: none,
      background: align(center + horizon)[Page intentionally left empty.],
    )
    // ...

    Another theoretical possibility would be to add a empty field on page which can be used to selectors like so:

    #show page.where(empty: true): set page(
      header: none,
      footer: none,
      background: align(center + horizon)[Page intentionally left empty.],
    )

    But I'm not sure if this ties in well with how pages work currently. I assume they aren't Locatable. This also leaves possibility for weird usages that must be considered #page(empty: true)[sike].

  11. laurmaedje commented on Apr 18, 2024

    @laurmaedje
    Member

    Hmm, duplicating all page properties on a page.empty element doesn't feel nice to me. Conceptually I like the idea of a show-set rule more, but it is indeed tricky.

  12. frozolotl commented on Jul 8, 2024

    @frozolotl
    Contributor

    I developed another workaround that seems to work better than @agrueneberg's solution when no page is inserted (still thanks for the inspiration, though!).

    #let is-page-empty() = {
      let page-num = here().page()
      query(<empty-page-start>)
        .zip(query(<empty-page-end>))
        .any(((start, end)) => {
          (start.location().page() < page-num
            and page-num < end.location().page())
        })
    }
    #show pagebreak: it => {
      [#metadata(none) <empty-page-start>]
      it
      [#metadata(none) <empty-page-end>]
    }
    
    #set page(
      numbering: "1 / 1",
      footer: context {
        if is-page-empty() {
          return
        }
        counter(page).display(page.numbering, both: true)
      },
    )
    
    #lorem(5)
    #pagebreak(to: "odd")
    #lorem(5)
  13. freundTech commented on Jul 8, 2024

    @freundTech
    Contributor

    I developed another workaround that seems to work better than @agrueneberg's solution when no page is inserted (still thanks for the inspiration, though!).

    That workaround sadly breaks links when used in a show heading rule.
    I guess one of the most common applications for this would be always starting chapters on odd numbered pages.

    #show heading.where(level: 1): it => {
      pagebreak(to: "odd")
      it
    }

    Your workaround inserts a metadata element before the pagebreak. Because metadata is not considered whitespace links pointing to a heading will now point to the page before the pagebreak instead of to the heading, which is on the page after the pagebreak.

  14. frozolotl commented on Jul 8, 2024

    @frozolotl
    Contributor

    That workaround sadly breaks links when used in a show heading rule.

    Oh, that is a good point. This is unfortunate. :/

    EDIT: Perhaps you could do a similar hack where the headings' page numbers are taken from a label that is inserted after the pagebreak and before the actual heading?

    EDIT: Answer, yes, this seems to work:

    #show outline.entry: it => {
      let heading-loc = query(selector(<heading-page>).after(it.element.location()))
        .first().location()
      let page-num = numbering("1", ..counter(page).at(heading-loc))
      link(heading-loc)[#it.body #box(width: 1fr, it.fill) #page-num]
    }
    
    #show heading: it => [#metadata(none) <heading-page>] + it
    #show heading.where(level: 1): it => pagebreak(weak: true, to: "odd") + it

    Obviously, you will need to use the same hack in all places where you are using the headings' page numbers.

  15. ensko commented on Jul 8, 2024

    @ensko
    SponsorContributor

    This last iteration is about fixing the page number associated with the headings, right? Besides the outline, the second problem is where the links point inside the resulting PDF. with the metadata before the pagebreak, the links will go to the previous page and not to the heading.

    I currently use a workaround that requires manually adding the metadata, so that it is not part of the heading and doesn't break links & page numbers. I do at least include a check that these chapter ends are placed properly: https://github.com/TGM-HIT/typst-diploma-thesis/blob/aee8bb654d40ac7efc905d7f88fa22f2edf9309b/src/utils.typ#L8-L111

  16. added
    styling
    and removed
    layout
    on Aug 6, 2024
  17. laurmaedje commented on Nov 12, 2024

    @laurmaedje
    Member

    @frozolotl's hack seems to work great in 0.12 :) The heading page issue was fixed in Typst.

  18. ensko commented on Nov 17, 2024

    @ensko
    SponsorContributor

    This indeed works great! Since the necessary pieces and 0.12 adaptations are a bit distributed throughout this thread, here is my take on it:

    // make pagebreaks detectable
    #show pagebreak: it => {
      [#metadata(none) <empty-page-start>]
      it
      [#metadata(none) <empty-page-end>]
    }
    
    // check whether this is an empty page
    #let is-page-empty() = {
      let page-num = here().page()
      query(selector.or(<empty-page-start>, <empty-page-end>)).chunks(2).any(((start, end)) => {
        start.location().page() < page-num and page-num < end.location().page()
      })
    }
    
    // skip footer on empty pages
    #set page(
      numbering: "1 / 1",
      footer: context if not is-page-empty() {
        counter(page).display(page.numbering, both: true)
      },
    )
    
    // demonstration
    #lorem(30)
    
    #pagebreak(to: "odd")
    
    #lorem(30)

    I have adjusted is-page-empty() a bit: I use an or selector to only do one query. I'm not sure, but I assumed that this is maybe more efficient? I'm sure Laurenz will correct me if not.

  19. terefang commented on Mar 16, 2025

    @terefang

    hello

    i have a similar use case.

    i need to style generated empty pages by pagebreak not only headers/footers.

    i am much in favour of something like that proposed in "Customize pages generated by pagebreak(to:) #4438" like:

    #pagebreak(weak:true,to:"odd", empty-content: () => fn())
    

    it was pointed out on discord (frozolotl) that something simple workaround like:

    #pagebreak(weak:false)
    #context {
      if calc.rem(counter(page).get(),2) == 0 [
        #page(/* options content here */)
        #pagebreak(weak:false)
      ]
    }
    

    will cause issues.

  20. ensko commented on Aug 14, 2025

    @ensko
    SponsorContributor

    I just tried the following, and it seems to work. If there are no edge cases that don't work, it might even be enough to (document it and) consider this issue closed:

    #set page(numbering: "1 / 1")
    // skip header and footer on empty pages
    #show pagebreak.where(to: "odd"): set page(header: none, footer: none)
    
    // demonstration
    #lorem(30)
    
    #pagebreak(to: "odd")
    
    #lorem(30)
  21. laurmaedje commented on Aug 14, 2025

    @laurmaedje
    Member

    That's pretty neat. What it doesn't solve is if a page ends up empty without a pagebreak (#2722 (comment)). I'm not sure how common that is as a requirement though.

  22. ensko commented on Aug 14, 2025

    @ensko
    SponsorContributor

    I see... sadly, this doesn't work for show pagebreak without the filter; I get "Maximum show rule depth exceeded" (although I'm not sure why, so maybe this could simply be "fixed"?)

    The only other way I see to insert empty pages, without using one or more pagebreaks, is #page[], right? (#block(height: 30cm) can give you empty pages, but that's not truly empty imo.)

    (EDIT: maybe figures can leave a page completely empty, but that user did not provide a reproduction: forum)

    I feel like the show pagebreak: set page(...) rule is very similar to tinger's show page.where(empty: true): set page(...). If that can be implemented, I think it would be very clear.

    (as an aside, set page(background: ...) also works with my approach, so it feels very close to what we need, except for the non-to pagebreaks and explicit empty pages)

  23. terefang commented on Aug 14, 2025

    @terefang

    looks like every impacted pagebreak would need to be replaced by:

    #context [
      #set page(numbering: none,footer: none,)
      #pagebreak()
      #if(calc.even(here().page())) [
        this space has been intentionally left blank.
        #pagebreak()
      ]
    ]
    
  24. ensko commented on Aug 14, 2025

    @ensko
    SponsorContributor

    @terefang this code will fail if you have many of them in your document. here().page() will first be e.g. even, then one iteration later there's an additional pagebreak() before it, so it's now odd, etc.

    If this is meant as a pagebreak(to: "odd") with content on it, you can do this:

    #show pagebreak.where(to: "odd"): set page(background: [this space has been intentionally left blank.])
    

    (adjust alignment and margins to taste)

  25. laurmaedje commented on Aug 14, 2025

    @laurmaedje
    Member

    I get "Maximum show rule depth exceeded" (although I'm not sure why, so maybe this could simply be "fixed"?)

    The reason is that set page itself also inserts weak pagebreaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requeststyling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions