tl;dr : Please have a look at this MWE which demonstrates the issue.
I am using typst to create class note for a course I am teaching. Here is my workflow : I type the content and intersperse it with assignment problems. The problems are custom environment, that saves the content in a state.
Then, (optionally) I will compile a PDF with only the assignments. In particular, I need to hide the text content that’s in between different problems. This is my current solution.
if assignment-mode {
box(height: 0pt, clip:true)[
#content
]
v(-1fr)
}
This makes sure that #content is compiled (which is needed for the #problems state to update), but nothing is displayed in the PDF.
Finally, this code displays the assignment.
#let show-problems() = {
if assignment-mode {
context[
#for problem in problems.get() {
assignment(problem)
}
]
}
}
This works. The issue is the hiding the content. I am not sure why, but the compiled PDF size increases as I add more and more text content.
Hi, welcome to the Typst forum! One possible solution could be to replace
if assignment-mode {
box(height: 0pt, clip:true)[
#content
]
v(-1fr)
}
with
if assignment-mode {
// Add a "show xxx: none" line for every kind of element that can come up
show text: none
show math.equation: none
content
}
Not very convenient, but you could write this in a little template function. It’s the best way I know to remove content from the output while keeping the side effects like state updates.
It might also work to simply add a Hide Function – Typst Documentation wrapper somehwere, I think this would make it not bei in the PDF at all, but I’m not totally sure
yes, hide is (somewhat) redaction suitable so it doesn’t actually put the result into the document (the width of the hidden content can still leak content—here’s some general thoughts on this: A way to redact text · Issue #4511 · typst/typst · GitHub)
if you combine it with place, the content will neither be rendered, nor take up space. That is probably the most comprehensive way to fully process content without having it in the document.
I would just check whether any headings hidden this way maybe make it into the PDF outline; that would probably be unintended. (Edit: seems like exactly that does happen: see PR #7201)
You can combine hide with place as @ensko suggested to avoid the content taking any space in layout. But I think that’s a less general solution than the show xxx: none rules since it fails when the content includes page styling or page breaks (because they are not allowed in a container, and place introduces a container).