Are there hidden show rules for adjacent citations?

I have noticed some hard to predict behavior when working with multiple citation styles in adjacent citations. See for example:

#let bibtex-file = bytes("
@article{Smith2023,
    author = {Smith, John and Doe, Jane},
    title = {The Art of Mock Bibtex Entries},
    journal = {Journal of Fictional Research},
    volume = {10},
    number = {2},
    pages = {123--145},
    year = {2023},
    publisher = {Imaginary Press}
}

@book{Jones2022,
    author = {Jones, Emily},
    title = {A Guide to Non-Existent Citations},
    publisher = {Scholarly Dreams Publishing},
    year = {2022},
    address = {New York, NY},
    edition = {1}
}")

A citation @Smith2023, another one @Jones2022,
and a prose citation: #cite(<Jones2022>, form: "prose"). \
This works fine.

Now for the weird part... \
Why is the second citation below "year" instead of "normal"? \
Why are there brackets? \
#cite(<Smith2023>, style: "springer-basic-author-date") #cite(<Smith2023>)

Another example, the second citation is "prose" instead of "normal", \
and a comma is added automatically:\
#cite(<Smith2023>, style: "springer-basic-author-date", form: "prose")
#cite(<Smith2023>, form: "normal")

#bibliography(bibtex-file, style: "nature")

This outputs:

A citation¹, another one², and a prose citation: Jones, E. ².
This works fine.

Now for the weird part…
Why is the second citation below “year” instead of “normal”?
Why are there brackets?
(Smith and Doe 2023, 2023)

Another example, the second citation is “prose” instead of “normal”,
and a comma is added automatically:
Smith and Doe (2023), Smith and Doe 2023

I’ve seen that depending on which citations styles you put next to each other, you get different results. I can’t really infer a consistent set of rules by playing with it.
What is happening here?



Side note…
Why am I doing this? I wanted to slightly tweak the “nature” citation style such that the “prose” form includes the year as well. I’ve managed to break this behavior by putting an invisible box[] in between:

#{cite(<Smith2023>, style: "springer-basic-author-date", form: "prose")
  box[]
  cite(<Smith2023>)}

Which produces: Smith and Doe (2023)¹

My understanding is that Typst uses the Citation Style Language (CSL), even for the built-in styles, see also the bibliography documentation. Those CSL files describe how adjacent citations should be displayed through the citation element and the nested layout element.

So regarding your questions

It seems when you put citations with different style next to each other, the style of the first one is used. But I am not sure if that is guaranteed behavior, so would be best to avoid relying on this and instead explicitly specify the style for all adjacent citations, or not specify it for any of them to use the implicit one for all of them.


Maybe the proper way to achieve this is to create a custom CSL file, based on the nature one.

It seems the Typst cite.form value is not a concept from CSL (I might be wrong though) and therefore cannot be directly controlled with it, but something Hayagriva – the library Typst uses for bibliography management – added, see source code.


  1. I think Typst does not directly use the CSL files from that repository but instead has embedded some of them, but I assume they should be identical. ↩︎

Thanks!

At least this explains at where this behavior comes from.
I’d have to dig deeper into the interaction between the CSL file and the Hayagriva source code to understand how I can modify the appearance of “prose” citations. At least I have a starting point now.

For the moment, I abstracted my hack (see the “side note”) into a function and this is a good enough workaround. But if I ever figure out how to do this the “proper” way, I’ll post it here.

What could also work instead of using a different cite.form value (and relying on Hayagriva to show the desired elements) is to use a dedicate CSL file only for cite.style where you want custom citations (but not for the whole bibliography or all citations) and whose <citation> specifies the desired format.

However, it seems the cite.style can affect also the style of entries in the bibliography to some extent (see for example related GitHub issue). So I am not sure if that could cause undesired behavior when your custom cite.style accidentally affects the style of the bibliography.