Can't use document()
inside a function
#2127
Replies: 8 comments 3 replies
-
If I understand correctly, it works as expected, since the set rules only affect its belonging scope.
|
Beta Was this translation helpful? Give feedback.
-
Relevant #1913 Setting a variable inside the scope of the function does not change the outer variable. And this is what is expected. Maybe you should follow conventional way of using #set_title or #show doc => template(title: "custom title", doc) in the beginning of the document instead of a function. |
Beta Was this translation helpful? Give feedback.
-
I know about the scope and everything like that, but aren't there any other way besides using Maybe it's just functional programming got a hold of me. |
Beta Was this translation helpful? Give feedback.
-
My main problem is that I have a template and a separate function for a title page with a dictionary of values: #import "@local/package:0.0.1": template, title-page
#show: template
#title-page((
title: "title",
a: 1,
b: "c",
d: (3, 4, 5),
)) Right now, I have to #let title = "title"
#show: template.with(title: title)
#title-page((
title: title,
)) Which I fill is a bit too verbose than just passing the title one to I don't know, I just want the code to be elegant and minimalistic. |
Beta Was this translation helpful? Give feedback.
-
Maybe I want to compose a title from some values that are passed to the In other words, if making the title makes sense in a function (and therefore setting the title there), because it has all the needed information (and there is literally "title" in |
Beta Was this translation helpful? Give feedback.
-
Have you consider passing doc as a argument? #let template(title: none, doc) = { #let title-page(title: none, doc) = { #show doc => template(title: “first title”, doc) #show doc => title-page(title: “second title”, doc) I did some quick test and this seems to be working. |
Beta Was this translation helpful? Give feedback.
-
I already mentioned this:
And the title is the same, so I would have to add another line with a variable, which I also already mentioned:
|
Beta Was this translation helpful? Give feedback.
-
Sorry I cannot comprehend. Perhaps make a wrapper to get the template and title-page into another (bigger) template and then calling it? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
This code doesn't do anything:
But it should've changed the title metadata/entry in the PDF file. Same way, I can't change the author of the document.
Reproduction URL
No response
Operating system
Linux
Typst version
Idea discussion: #2153.
Beta Was this translation helpful? Give feedback.
All reactions