How to hide all second level sections?

Hello. I’ve been using Typst for a while now (with great satisfaction) to manage a file containing all my work notes. Each first-level section is a note. Periodically, I export the file to PDF to share it with my classes (I teach mathematics). However, I don’t want to share everything; I’d like to keep some sections hidden and prevent them from appearing in the final PDF file.

One solution is to move all the private notes to the end of the file and enclose them within an if statement, using a variable to decide whether or not to show this final section. I’ve done and it seems to work. However, I’d prefer to keep the notes in the order they were inserted, both the public and private ones.

I was wondering if there’s a simple mechanism to solve my problem. For example, if I were to put the private notes as second-level notes (== Private Note), is there a way, using the show rule mechanism, to hide all second-level notes if a certain variable is set in a particular way?

Thanks a lot for any possible help, I hope I’ve explained myself clearly, and I apologize for any uncertainties in my English.

R

Hello. The easiest way is to use if statement on-site:

#let show-private = true
// #let show-private = false
#let private(body) = if show-private { body }

public
#private[
private
]
public

Heading-based approach likely be a very hacky solution and probably won’t work reliably. Prioritize simplicity over minor convenience, when possible, to keep Typst code clean and readable.

2 Likes