I started with the minimal goal to only render the customized cover as a single page PDF. That’s done.
Now I would like to extend the template so that one could #import "@preview/lumen:0.1.1": cover and call the #show: cover(...) function anywhere in a document.
Basically, the following snippet should produce a three-page document with text, then cover and then text:
For now, the first lorem works and a pagebreak occurs as well. But the document seems to end after cover and nothing is rendered of the second lorem. Note, that the page size should be the same for the whole document.
I have the feeling that it has something to do with using page() in the lib.typ file. That file is a singe #let cover(...) function definition. Inside of it I make use of page to align all cover elements wrapped inside a block element. Does that make my document seemingly end after cover ?
I would be grateful if you could explain what is going wrong and provide an example of a template that achieves the same goal.
cover is not a template/style function, and by the documentation it’s not a package for use in a document that’s more than just a cover.
It looks like to me that:
#show: cover(...)
This just means and has the effect of: replace the rest of the document from here with the result of the function call cover(...).
Since cover is not a template function (doesn’t use the document as input to the function), it seems like it should be called like #cover() and not with show? I haven’t used this package though.
See also template documentation: Making a Template – Typst Documentation An actual template function has a document parameter, called doc in the example where the template/style function is called conf. Sometimes that parameter is called body or it too, it’s just a choice.
I must admit that I had a very hard time with the template documentation and the role of body. However, your solution has brought me a step closer to understanding it. Thanks !
Here’s the step by step from regular configuration to a template/style function
// in the document
#set text(size: 12pt)
// rest of document here
// in the document
#show: doc => {
set text(size: 12pt)
doc
}
// rest of document here
// in the document
#let my-template(doc) = {
set text(size: 12pt)
doc
}
#show: my-template
// rest of document here
Move the function to a different file
template.typ
#let my-template(doc) = {
set text(size: 12pt)
doc
}
main.typ
#import "template.typ": my-template
#show: my-template
// rest of document here
It’s no wonder it’s confusing for those not used to it (and I wasn’t used to it until using it for a while…) it sort of turns function calling inside out doesn’t it? That’s why it’s not invoked using regular function call syntax, but you use show. show is “take all the following document and give as a parameter to the function”.