Skip to content

Within selector for introspection - #8250

Merged
laurmaedje merged 1 commit into
mainfrom
expose-within-selector
May 18, 2026
Merged

laurmaedje merged 1 commit into
mainfrom
expose-within-selector

Conversation

@laurmaedje

@laurmaedje laurmaedje commented May 12, 2026 •

Copy link
Copy Markdown
Member

This selector is super useful, so I don't want to hold it back even though it's currently only supported in introspections, not in show rules. It's the same as before and after in this regard, but unlike these, it can be supported in show rules in the future.

Closes #1926. The show rule part will be tracked in #8251.

@laurmaedje laurmaedje changed the title Expose and document selector.within Within selector for introspection May 12, 2026
@bastienvoirin

bastienvoirin commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Does it mean that for document-aware outlines in bundle export we can now write

#show document: it => context {
  outline(target: selector(heading).within(here()))
  it.body
}

@laurmaedje

Copy link
Copy Markdown
Member Author

Not quite like that because you're discarding the document element, but in principle something like that can work yes.

Alternatively, you can also directly use the document's location with within to find things in a specific document. What is not yet exposed is a nice way to get the location of the current documentation from within it, but it's possible by querying for the last document before here(). So you could write something like this:

#let local-outline() = context {
  let doc = query(selector(document).before(here())).last()
  outline(target: selector(heading).within(doc.location()))
}

#document("a.pdf")[
  #local-outline()

  = A
  = B
]

#document("b.pdf")[
  #local-outline()

  = C
  = D
  = E
]

Worth saying that querying documents is not the best for incremental compilation ... it's not a disaster, but the outline will likely be recomputed for every edit to the document its contained in.

@bastienvoirin

Copy link
Copy Markdown
Contributor

Awesome, thank you! What would a better way with respect to incremental compilation look like?

@isuffix isuffix added the introspection Related to the introspection category label May 17, 2026
@laurmaedje

Copy link
Copy Markdown
Member Author

Awesome, thank you! What would a better way with respect to incremental compilation look like?

Something that doesn't let the introspection observe the document's body. Internally, there is something like here().document() which gives the document's location right away without looking at the document itself. The location is stable across edits while the body isn't. But I'm not sure I like that API, so it's not currently exposed.

@laurmaedje
laurmaedje added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit 64720d4 May 18, 2026
18 checks passed
@laurmaedje
laurmaedje deleted the expose-within-selector branch May 27, 2026 11:30
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 9, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 10, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

introspection Related to the introspection category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ancestry/inside/within selector

3 participants