typst_library/layout/
hide.rs

1use crate::diag::SourceResult;
2use crate::engine::Engine;
3use crate::foundations::{elem, Content, Packed, Show, StyleChain};
4
5/// Hides content without affecting layout.
6///
7/// The `hide` function allows you to hide content while the layout still 'sees'
8/// it. This is useful to create whitespace that is exactly as large as some
9/// content. It may also be useful to redact content because its arguments are
10/// not included in the output.
11///
12/// # Example
13/// ```example
14/// Hello Jane \
15/// #hide[Hello] Joe
16/// ```
17#[elem(Show)]
18pub struct HideElem {
19    /// The content to hide.
20    #[required]
21    pub body: Content,
22
23    /// This style is set on the content contained in the `hide` element.
24    #[internal]
25    #[ghost]
26    pub hidden: bool,
27}
28
29impl Show for Packed<HideElem> {
30    #[typst_macros::time(name = "hide", span = self.span())]
31    fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
32        Ok(self.body.clone().styled(HideElem::set_hidden(true)))
33    }
34}