Skip to content

Support for multiple bibliographies - #8307

Merged
laurmaedje merged 1 commit into
mainfrom
multi-bib
May 26, 2026
Merged

laurmaedje merged 1 commit into
mainfrom
multi-bib

Conversation

@laurmaedje

@laurmaedje laurmaedje commented May 18, 2026 •

Copy link
Copy Markdown
Member

This PR adds support for including multiple bibliographies in a single Typst document. When a Typst document contains multiple bibliographies, each citation is assigned to one of them. By default, Typst will automatically pick a suitable bibliography (typically, the closest following one that contains the referenced citation key). This covers common cases like by-chapter or thematic bibliographies. For more fine-grained control, citations can be explicitly targeted by a bibliography through a target selector.

Closes #1097.

Design

The PR supersedes #7277, but follows largely the same design:

  • There is still the bibliography.target field for fine-grained control over which bibliography picks up which citation. Thanks to @thuiop for this idea, it's a really nice general mechanism.

  • The kind field from said PR was adjusted to match my original design intent and renamed to group because kind felt a bit too generic after all. The purpose of the group field is to define groups of bibliographies that have shared citation numbering (you can view the updated docs for more info). I'm still not super happy with the design, but exposing some control over this seems important and it's not too bad.

Implementation

Code-wise, the PR is fairly far removed from #7277, but conceptually there is really mostly just one core difference. When there are consecutive citations that will be picked up by different bibliographies, #7277 would already separate them during citation grouping in realization. While this is conceptually quite nice and clean, it would unfortunately incur an additional document iteration. This is too high a price to pay, so I've moved this logic into the bibliography generation (which is a bit annoying).

Beyond this, I've done some preparatory refactoring of the bibliography generation at large in #8283 to make all of this fit in more nicely, added various diagnostics, tests, docs, etc.

Before this is ready for merge, I still gotta land typst/hayagriva#409 and I have one TODO left there because the interaction of the offsetting with bibliography styles that are unnumbered does not seem ideal yet.

Example

As mentioned, for basic use cases like by-chapter or thematic bibliographies, no target selector is necessary, but here's an example of how the target selector could be used in combination with the within selector to have a bibliography local to an info box.

Code Output
#let info(body) = block(
  stroke: (left: 1.5pt + blue),
  fill: aqua.lighten(50%),
  inset: 1em,
  context {
    body
    show divider: set block(spacing: 1.2em)
    divider()
    bibliography(
      "works.bib",
      title: none,
      target: selector(cite).within(here()),
      style: "mla",
    )
  }
)

= On the matter of dumplings
In recent years, we can observe an uptick in
dumpling consumption across the board. @netwok

#info[
  Dumplings are particularly enjoyed
  among pirates. @arrgh
]

#bibliography("works.bib")
Document with main text and main bibliography and an info box that contains a local bibliography

@MDLC01 MDLC01 added the bibliography Anything about citations and bibliographies. label May 19, 2026
Base automatically changed from refactor-bib to main May 22, 2026 15:48
@laurmaedje
laurmaedje marked this pull request as ready for review May 26, 2026 14:38
@laurmaedje
laurmaedje enabled auto-merge May 26, 2026 14:42
@laurmaedje
laurmaedje added this pull request to the merge queue May 26, 2026
Merged via the queue into main with commit 85a15ba May 26, 2026
18 checks passed
@laurmaedje
laurmaedje deleted the multi-bib branch May 26, 2026 15:13
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 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
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
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
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
Part of the Typst 0.15 cleanup stack. This slice covers diagnostics/span
migration and the minimal query prerequisites needed before the later
export and text accessor slices.

## Upstream Typst Changes

- [`typst/typst#8052`](typst/typst#8052) makes
diagnostic hints carry span metadata. Tinymist renders the hint message
payload instead of formatting the whole spanned wrapper.
- [`typst/typst#8254`](typst/typst#8254) changes
diagnostic, user-action, and test-range span handling. Tinymist updates
LSP diagnostics, user-action conversion, and range-sensitive tests for
the new span shape.
- [`typst/typst#8188`](typst/typst#8188) changes
syntax diagnostics. Tinymist updates syntax matchers and diagnostics
conversion paths that inspect syntax-side errors.
- [`typst/typst#8307`](typst/typst#8307) changes
bibliography lookup. Tinymist now finds bibliography elements through
the document introspector and packs them back to `BibliographyElem`.
- Typst 0.15 deprecates rooted virtual-path access through
`as_rooted_path`; diagnostics now use the slash-form virtual path
accessor for extension checks.

## Tinymist Changes

- Updates `tinymist-world` diagnostic rendering for spanned hint values.
- Updates `tinymist-query`, `tinymist-analysis`, `tinymist-lint`, and
debug-facing syntax diagnostics for the new span and syntax diagnostic
APIs.
- Updates user-action span conversion and affected test ranges.
- Updates code-context path evaluation to construct `RangeMapper` from
an iterator, matching the lint expectations of the current toolchain.
- Carries the small bibliography lookup prerequisite in this slice so
later query-oriented slices build on the updated Typst API.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
Part of the Typst 0.15 cleanup stack. This slice covers diagnostics/span
migration and the minimal query prerequisites needed before the later
export and text accessor slices.

## Upstream Typst Changes

- [`typst/typst#8052`](typst/typst#8052) makes
diagnostic hints carry span metadata. Tinymist renders the hint message
payload instead of formatting the whole spanned wrapper.
- [`typst/typst#8254`](typst/typst#8254) changes
diagnostic, user-action, and test-range span handling. Tinymist updates
LSP diagnostics, user-action conversion, and range-sensitive tests for
the new span shape.
- [`typst/typst#8188`](typst/typst#8188) changes
syntax diagnostics. Tinymist updates syntax matchers and diagnostics
conversion paths that inspect syntax-side errors.
- [`typst/typst#8307`](typst/typst#8307) changes
bibliography lookup. Tinymist now finds bibliography elements through
the document introspector and packs them back to `BibliographyElem`.
- Typst 0.15 deprecates rooted virtual-path access through
`as_rooted_path`; diagnostics now use the slash-form virtual path
accessor for extension checks.

## Tinymist Changes

- Updates `tinymist-world` diagnostic rendering for spanned hint values.
- Updates `tinymist-query`, `tinymist-analysis`, `tinymist-lint`, and
debug-facing syntax diagnostics for the new span and syntax diagnostic
APIs.
- Updates user-action span conversion and affected test ranges.
- Updates code-context path evaluation to construct `RangeMapper` from
an iterator, matching the lint expectations of the current toolchain.
- Carries the small bibliography lookup prerequisite in this slice so
later query-oriented slices build on the updated Typst API.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
Part of the Typst 0.15 cleanup stack. This slice covers diagnostics/span
migration and the minimal query prerequisites needed before the later
export and text accessor slices.

## Upstream Typst Changes

- [`typst/typst#8052`](typst/typst#8052) makes
diagnostic hints carry span metadata. Tinymist renders the hint message
payload instead of formatting the whole spanned wrapper.
- [`typst/typst#8254`](typst/typst#8254) changes
diagnostic, user-action, and test-range span handling. Tinymist updates
LSP diagnostics, user-action conversion, and range-sensitive tests for
the new span shape.
- [`typst/typst#8188`](typst/typst#8188) changes
syntax diagnostics. Tinymist updates syntax matchers and diagnostics
conversion paths that inspect syntax-side errors.
- [`typst/typst#8307`](typst/typst#8307) changes
bibliography lookup. Tinymist now finds bibliography elements through
the document introspector and packs them back to `BibliographyElem`.
- Typst 0.15 deprecates rooted virtual-path access through
`as_rooted_path`; diagnostics now use the slash-form virtual path
accessor for extension checks.

## Tinymist Changes

- Updates `tinymist-world` diagnostic rendering for spanned hint values.
- Updates `tinymist-query`, `tinymist-analysis`, `tinymist-lint`, and
debug-facing syntax diagnostics for the new span and syntax diagnostic
APIs.
- Updates user-action span conversion and affected test ranges.
- Updates code-context path evaluation to construct `RangeMapper` from
an iterator, matching the lint expectations of the current toolchain.
- Carries the small bibliography lookup prerequisite in this slice so
later query-oriented slices build on the updated Typst API.

---------

Co-authored-by: paran3xus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bibliography Anything about citations and bibliographies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple bibliographies

2 participants