Skip to content

Allow leading labels to attach to their enclosing elements #9113

Backlog

Description

@AprilGrimoire

Description

Currently, Typst attaches a label to the closest preceding labelable element within the same scope. If a label is placed at the beginning of a content sequence, it has no preceding element to attach to.

I propose that, in such cases, the label attach to the enclosing element instead, where one exists.

For example,

#block[<foo> Some content]

would be equivalent to:

#block[Some content] <foo>

This would preserve the existing behavior of labels following elements while giving a useful meaning to otherwise unattached leading labels.

Use case

In mathematical writing, it is common to divide a theorem or proposition into several individually labeled assertions. Placing labels at the beginning of enumeration items is often more natural, particularly when an item contains multiple paragraphs:

+ <first> First assertion.
+ <second> Second assertion.

Under the proposed semantics, these labels would attach directly to their respective enum.item elements.

Currently, the itemize package provides elabel as a workaround, which allows one to write:

+ #itemize.elabel(<first>) First assertion.
+ #itemize.elabel(<second>) Second assertion.

Internally, this function creates an invisible metadata element to which the label is attached. It would be desirable to support leading labels natively through a general rule rather than requiring such workarounds.

This proposal is independent of #779, which concerns making enumeration items referenceable. It is instead a general change to the semantics of label attachment that would also benefit querying and styling.

A related proposal is #1943, which discusses extending the search for suitable label targets.

Activity

  1. Lege19 commented on Nov 26, 2026

    @Lege19
    Contributor

    Applying this for syntax sugars and for blocks are separate features IMO.

    I like this for syntax sugar for making it easier to label list items.
    Now you mention it I wonder why this isn't the syntax for labelleing a heading.

    For blocks I'm not sure this is needed.

  2. AprilGrimoire commented on Nov 26, 2026

    @AprilGrimoire
    Author

    For blocks I'm not sure this is needed.

    I'm not too familiar with Typst's typesetting model, but I'm imagining list items and such are all blocks? I think that's a paradigm in Typst. https://forum.typst.app/t/confusion-about-syntax-making-formulae-page-breakable/7571

  3. Lege19 commented on Nov 26, 2026

    @Lege19
    Contributor

    yes, they are blocks. I meant blocks in the syntactic sense of [...]

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions