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
That approach did not work, because locate does return content (related to #1613 I think), not the type of what is contained inside the locate (dict of margins).
In general, repeating the locate seems quite verbose, so I tried something different:
In general, I wondered even before trying if this approach (with set page inside locate) might work at all, because I don't know where the locate would be placed, if not on the page. As I understand it, there is no page context for the locate at all, so where is it located?
Is there a different way to achieve the desired result?
My use case is a letter btw., that should have address fields only on the first page. I guess I could add the address fields and such to the content itself, pad with negative margins, but that feels quite backwards.
The reason is that invisible metadata is generated through locate to which the page set rule doesn't apply. It's a bit unfortunate interaction.
Note that putting large parts of the document into locate is generally not something I would recommend. It is not well tested and will also degrade performance.
Is there a different way to achieve the desired result?
Proper dynamic page margins are unfortunately not possible at the moment.
v10.0 allows for style(d=> …)set page() rules, while v11.0 doesn't do any more (context or style(d=> …) and set page(); content or page(content) make no difference).
So the context unification led to the former style() getting dragged down instead of the former locate() getting hauled up (i.e. also not triggering the empty page appendage).
Examples
Minimal
#context page(
margin: 1cm,// set anything to trigger the bug
"Empty Page Appendage Bug",
)
Simplified Practical Comparison with v10.0
This is working gracefully with v10.0, but not with v11.0.
(For simplicity, this example is tailored to A4 with default margins.)
#import calc: sqrt, rem
#show: all=> style(sts=> {
let running-ht = measure([g], sts).height
let running-ln-ht = measure([g\ g], sts).height - running-ht
let running-leading = running-ln-ht - running-ht
let t-area-envis-ht = 297mm - 50mm
let t-area-addit-ht = (running-ln-ht.mm() - rem(t-area-envis-ht.mm(), running-ln-ht.mm())) * 1mm
let t-area-ht = t-area-envis-ht + t-area-addit-ht - running-leading
set page(
margin: (bottom: 100% - 25mm - t-area-ht, rest: auto),
)
all
})
#lorem(999)
Comparison with v10.0—Subsequent set page() Rule
Also this is working gracefully with v10.0, but not with v11.0.
The set page() rule is part of chic()—utilized here in order to show off an interplay with a package.
Primarily, a module of mine is assessing & setting the type area (i.e. the area left between the margins) in the fashion of the 2nd example above. It slightly adjusts its height based on the line height (with the current text/par settings); so the (bottom) margin depends on a measure()ment.
I can mitigate the effects of this bug by ‘pulping’ the additionally appended page using a preceding set rule (#set page(height: auto, margin: 0pt);#context {page(paper: "a4", margin: auto, <…>)}) and subtracting one from the page total wherever shown/used. But printing reveals the existence of that page (in form of sheet demand).
So my work is hindered as I see no alternative approach. Also, I can't switch back to v10.0 because I pressingly need the contextual property access feature.
Here to say that setting page inside a content block and adding anything (even invisible and non-space-consuming) after that [] block will result in an empty page at the end as well: #4407.
Activity
alexanderwiller commentedon Nov 18, 2023
I am trying something similar, I want both different header content and different margins depending on if I'm on the first page or not.
First, I did this to achieve a different header between the first and following pages:
set page(paper: "a4", header: locate(loc => { if counter(page).at(loc).first() == 1 { header_1stpage } else { header } }), )That approach worked, but I wanted to have margins that differ per-page too, so I tried to make the margin dynamic based on the page too:
set page(paper: "a4", margin: locate(loc => { if counter(page).at(loc).first() == 1 { (left: 25mm, top: 98.46mm, rest: 20mm) } else { (left: 25mm, top: 40mm, rest: 20mm) } }), header: locate(loc => { if counter(page).at(loc).first() == 1 { header_1stpage } else { header } }), )That approach did not work, because
locatedoes return content (related to #1613 I think), not the type of what is contained inside the locate (dict of margins).In general, repeating the
locateseems quite verbose, so I tried something different:set page(paper: "a4", margin: (left: 25mm, rest: 20mm)) locate(loc => {if counter(page).at(loc).first() == 1 { set page(header: header_1stpage, margin: (top: 98.46mm)) } else { set page(header: header, margin: (top: 40mm)) }})While I really like the cleanliness, this approach works only partially:
I created a complete example that shows the situation: https://typst.app/project/rjX6qQRpfnYDu9HZJIoK4l
In general, I wondered even before trying if this approach (with
set pageinsidelocate) might work at all, because I don't know where the locate would be placed, if not on the page. As I understand it, there is no page context for thelocateat all, so where is it located?Is there a different way to achieve the desired result?
My use case is a letter btw., that should have address fields only on the first page. I guess I could add the address fields and such to the content itself, pad with negative margins, but that feels quite backwards.
laurmaedje commentedon Feb 13, 2024
The reason is that invisible metadata is generated through
locateto which the page set rule doesn't apply. It's a bit unfortunate interaction.Note that putting large parts of the document into
locateis generally not something I would recommend. It is not well tested and will also degrade performance.Proper dynamic page margins are unfortunately not possible at the moment.
l0wx commentedon Mar 26, 2024
Description
v10.0 allows for
style(d=> …)set page()rules, while v11.0 doesn't do any more (contextorstyle(d=> …)andset page(); contentorpage(content)make no difference).So the
contextunification led to the formerstyle()getting dragged down instead of the formerlocate()getting hauled up (i.e. also not triggering the empty page appendage).Examples
Minimal
Simplified Practical Comparison with v10.0
This is working gracefully with v10.0, but not with v11.0.
(For simplicity, this example is tailored to A4 with default margins.)
Comparison with v10.0—Subsequent
set page()RuleAlso this is working gracefully with v10.0, but not with v11.0.
The
set page()rule is part ofchic()—utilized here in order to show off an interplay with a package.Background
Primarily, a module of mine is assessing & setting the type area (i.e. the area left between the margins) in the fashion of the 2nd example above. It slightly adjusts its height based on the line height (with the current
text/parsettings); so the (bottom) margin depends on ameasure()ment.I can mitigate the effects of this bug by ‘pulping’ the additionally appended page using a preceding
setrule (#set page(height: auto, margin: 0pt);#context {page(paper: "a4", margin: auto, <…>)}) and subtracting one from the page total wherever shown/used. But printing reveals the existence of that page (in form of sheet demand).So my work is hindered as I see no alternative approach. Also, I can't switch back to v10.0 because I pressingly need the contextual property access feature.
Andrew15-5 commentedon Jun 17, 2024
Here to say that
settingpageinside acontentblock and adding anything (even invisible and non-space-consuming) after that[]block will result in an empty page at the end as well: #4407.[-]`set page` inside `locate` appends empty page[/-][+]`set page` inside `context` appends empty page[/+]