-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make options accessible within templates #10302
Comments
Why should you expect to be able to determine inside the template which command line options were used? |
Because a considerable amount of them is supposed to affect the layout of the document. If it's not how it's supposed to work, I'd appreciate any tips. I understand, that the option in question is in the "Options affecting specific writers" section and typst is not mentioned as a writer affected by it, but the only way I see to add it, is for this option to be able to influence the output. This can be done either by spitting out a hardcoded typst chunk or affecting the template. Again, I'm not yet familiar with pandoc's internal organisation enough to know if it's the correct approach. Technically, reading an option from the template is not a hard requirement, the other way is to introduce a variable that gets set with an option. |
Maybe it would help me if you explained a bit more why you need to know, inside the template, what the top-level division setting is. In principle, we could change pandoc so that it populates a template variable, say |
In my case, I'd like the #show heading.where(level: 1): it => [
#pagebreak(weak: true)
#it
] Currently, this chunk could be used inside this template conditional, where
|
One low-tech change we could make would be to have the typst writer set a |
Yeah, that's basically what I want. The issue is that I'm pretty sure someone (perhaps myself) will bump into some similar situation rather soon with some other option. |
Here's a diff that will expose an
Not completely sure this is a good idea, but it was easy. Note that in most formats it is not going to be possible to test the value of a variable, because the template language has no |
Here's the output from a template that just iterates over the key/value pairs in
@tarleb I'm curious what you think about the idea of exposing |
It seems slightly weird to me, but not too bad, and I'll admit that it could be quite useful. I like that Opt type is part of the public (Haskell) interface, so any change would require a major version bump, making it reasonably stable and predictable. Once concern would be performance, but I assume the effect would be negligible. The other is that this has the potential to cause confusion when this feature is combined with custom writers, because then the actual WriterOptions values might differ from the command line values. |
@tarleb wrote:
How so and why? It seems to me that this is something you need to be aware of when creating custom writers. I've read the documentation for custom writers several times while trying to write one for (Perl) Pod, but maybe I missed it anyway. |
Example: function Writer (doc, opts)
opts.number_sections = true
return pandoc.Write(doc, 'latex', opts)
end If someone now accesses |
Oh, I thought Perhaps |
The For clarity: I should have used |
Bumped into an issue that I can't access the
--top-level-division
setting inside the typst template (necessary to implement page breaks when set to "chapter"). There's a workaround: the template can expose an arbitrary variable which can be set with the-V
argument, but this potentially breaks the API contract (that this option is what determines the respective part of the layout).The docs for
--top-level-division
state:This reads as the feature is implemented for the mentioned formats, but it's not clear if the setting is accessible from templates of those or any other formats.
The text was updated successfully, but these errors were encountered: