You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Bastien Voirin, Philipp Niedermayer, hurzl, Fabian Löschner, Orjan Ameye, gingercat, Tibo, Kyle L. Davis, bjoluc, temp66 and 1 more
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.
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.
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
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.
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].
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.
I developed another workaround that seems to work better than @agrueneberg's solution when no page is inserted (still thanks for the inspiration, though!).
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.
#showheading.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.
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?
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.
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#showpagebreak: it=> {
[#metadata(none) <empty-page-start>]
it
[#metadata(none) <empty-page-end>]
}
// check whether this is an empty page#letis-page-empty() = {
letpage-num= here().page()
query(selector.or(<empty-page-start>, <empty-page-end>)).chunks(2).any(((start, end)) => {
start.location().page() <page-numandpage-num<end.location().page()
})
}
// skip footer on empty pages#setpage(
numbering: "1 / 1",
footer: contextifnotis-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.
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:
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.
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'sshow 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)
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()
]
]
@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.])
Activity
Leedehai commentedon Nov 30, 2023
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.
PgBiel commentedon Dec 7, 2023
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.
Leedehai commentedon Dec 7, 2023
@PgBiel reasonable, I don't have a strong opinion on this one so I'll add the option in my PR #2882 :)
laurmaedje commentedon Dec 13, 2023
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 fromtoor 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?
laurmaedje commentedon Dec 13, 2023
What also ties in with this is the ability to have something like "This page intentionally left blank" printed on the page.
agrueneberg commentedon Jan 25, 2024
Is there a workaround for custom headers? I experimented with
metadataandstate, but couldn't find a good solution.agrueneberg commentedon Jan 25, 2024
Nevermind, I got it to work. Here's a my
metadatabased workaround for a document with a cover page that has new chapters starting on the right side:tingerrr commentedon Apr 18, 2024
What about creating a
page.emptysub-element which inherits all styles frompageby virtue of them beingauto.Such an element could be created when
pagebreak(to: _)creates intentional empty pages. As well as when a user explicitly inserts it or multiple strongpagebreaks.Then, simple
show/setrules would allow us to set heading and footer tonone, or setting the default content using the background/foreground.Another theoretical possibility would be to add a
emptyfield onpagewhich can be used to selectors like so: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].laurmaedje commentedon Apr 18, 2024
Hmm, duplicating all page properties on a
page.emptyelement doesn't feel nice to me. Conceptually I like the idea of a show-set rule more, but it is indeed tricky.frozolotl commentedon Jul 8, 2024
I developed another workaround that seems to work better than @agrueneberg's solution when no page is inserted (still thanks for the inspiration, though!).
freundTech commentedon Jul 8, 2024
That workaround sadly breaks links when used in a
show headingrule.I guess one of the most common applications for this would be always starting chapters on odd numbered pages.
Your workaround inserts a
metadataelement before the pagebreak. Becausemetadatais 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.frozolotl commentedon Jul 8, 2024
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
pagebreakand before the actual heading?EDIT: Answer, yes, this seems to work:
Obviously, you will need to use the same hack in all places where you are using the headings' page numbers.
ensko commentedon Jul 8, 2024
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
laurmaedje commentedon Nov 12, 2024
@frozolotl's hack seems to work great in 0.12 :) The heading page issue was fixed in Typst.
ensko commentedon Nov 17, 2024
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:
I have adjusted
is-page-empty()a bit: I use anorselector to only do onequery. I'm not sure, but I assumed that this is maybe more efficient? I'm sure Laurenz will correct me if not.terefang commentedon Mar 16, 2025
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:
it was pointed out on discord (frozolotl) that something simple workaround like:
will cause issues.
ensko commentedon Aug 14, 2025
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:
laurmaedje commentedon Aug 14, 2025
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.
ensko commentedon Aug 14, 2025
I see... sadly, this doesn't work for
show pagebreakwithout 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'sshow 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-topagebreaks and explicit empty pages)terefang commentedon Aug 14, 2025
looks like every impacted pagebreak would need to be replaced by:
ensko commentedon Aug 14, 2025
@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 additionalpagebreak()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:(adjust alignment and margins to taste)
laurmaedje commentedon Aug 14, 2025
The reason is that
set pageitself also inserts weak pagebreaks.