Skip to content

Documents without content discard rules #2710

Closed

Description

@tingerrr

A document containing no content but set rules like:

#set document(author: ("author 1", "author 2", "author 3"))

seem to not have any styles when going into layouting, resulting in those values not being written to the PDF. For this specific example, in the following code, styles returns an empty vector for author on L94.

fn layout_root(&self, vt: &mut Vt, styles: StyleChain) -> SourceResult<Document> {
tracing::info!("Document layout");
let mut pages = vec![];
let mut page_counter = ManualPageCounter::new();
let children = self.children();
let mut iter = children.iter().map(|c| &**c).peekable();
while let Some(mut child) = iter.next() {
let outer = styles;
let mut styles = styles;
if let Some((elem, local)) = child.to_styled() {
styles = outer.chain(local);
child = elem;
}
if let Some(page) = child.to::<PageElem>() {
let extend_to = iter.peek().and_then(|&next| {
next.to_styled()
.map_or(next, |(elem, _)| elem)
.to::<PageElem>()?
.clear_to(styles)
});
let fragment = page.layout(vt, styles, &mut page_counter, extend_to)?;
pages.extend(fragment);
} else {
bail!(child.span(), "unexpected document child");
}
}
Ok(Document {
pages,
title: self.title(styles),
author: self.author(styles).0,
keywords: self.keywords(styles).0,
date: self.date(styles),
})
}
}

See:

Without the content like shown above, Typst will not write the Author information at all.

Originally posted by @GFPJ in #2556 (comment)

Activity

  1. added
    bug
    styling
    on Nov 24, 2023
  2. added a commit that references this issue on Aug 16, 2024
    30f103d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstyling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions