Skip to content

Can't set document properties based on context #4065

Closed

Description

@frozolotl

Description

There currently is no way to set any document properties using context-dependent functions.
If one tries to define a show-rule as follows, the PDF export will not have a title set. Using context document.title does still output the set title, though.

// NOTE: You probably don't want to actually do such a `show: body => context …` construction.
#show: body => context {
  set document(title: [Title]) if query(<my-label>).len() == 0
  body
}
#context document.title
// uncomment if desired: <my-label>

Proposal

There should probably be a way to define document properties based on context.

If that is not feasible, then context set document() should throw a compiler error.

Reproduction URL

No response

Operating system

No response

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on May 3, 2024
  2. Andrew15-5 commented on May 3, 2024

    @Andrew15-5
    Contributor

    Here is the minified version:

    #let template(doc) = {
      // context if state("bundle").get() != true {
      context if query(<sub-document-begin>).len() == 0 {
        set document(title: [Title])
      }
      // set ...
      // set ...
      // set ...
      // show ...
      // show ...
      // show ...
      doc
    }
    #show: template
    Text
  3. added
    styling
    on May 7, 2024
  4. Andrew15-5 commented on May 16, 2024

    @Andrew15-5
    Contributor

    Similar issue: #2326.
    (set page() inside context vs. set document() (inside if statement that is) inside context)

  5. 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