Consider the following situation: My document contains several parts each of which requires a separate bibliography with distinct references. However, typst does not support multiple bibliographies yet. Hence, only the first part can use typst's built-in bibliography function.
As a workaround, I tried to create a bibliography for the latter parts manually. To this end, I use the cite
function with form: full
to mimic bibliography entries and put the bibliography together by hand. This works well but I cannot find a good solution to add inline references to my custom bibliography in the text. Apparently, cite
is not useful here as it automatically creates a bibliography entry in the built-in bibliography from the first part, which is obviously not desired.
Is there a way to prevent this behavior? What I would need is some function that simply inserts an inline reference with a certain citation style without the automatic creation of a bibliography entry.
The fallback would be to write a function that mimics the inline references in the desired style, which would be really ugly and cumbersome.
If you specify #show bibliography: none
, you can load the full bibliography and hide the initial printout
#show bibliography: none
#bibliography("refs.bib")
= First Section
#cite(<plucked-string>, form: "full")
= Second Section
#cite(<plucked-string-extensions>, form: "full")
You can create a state
that tracks all your citations from a section, and a function that prints those references on demand. Then, by flushing this state each time you create a heading, you can get automatically-populated sectional bibliographies!
#show bibliography: none
#bibliography("refs.bib")
// Keep track of all references, clearing every time a new heading is shown
#let section-refs = state("section-refs", ())
// Add bibliography references to the current section's state
#show ref: it => {
it
if it.element != none {
// Citing a document element like a figure, not a bib key
// So don't update refs
return
}
section-refs.update(old => {
old.push(it.target)
old
})
}
// Clear the previously stored references every time a level 1 heading
// is created
#show heading.where(level: 1): it => {
section-refs.update(())
it
}
#let section-bib() = locate(loc => {
for target in section-refs.at(loc) {
block(cite(target, form: "full"))
}
})
= First Section
My reference @plucked-string and another @plot
#section-bib()
= Second Section
Another reference @plucked-string-extensions
#section-bib()