How to write Typst markup in bibliography?

It appears that Typst commands are ignored in Hayagriva content:

bibfile.yml:

breathing:
  type: article
  title: Breathing in O#sub[2] releases CO2
  author:
  - Smith, Joe
  - Smith, Jane
  date: 2025
  parent:
    type: periodical
    title: Journal of Lungs
    volume: 1

document.typ:

@breathing
#bibliography("bibfile.yml")

yields:

But show rules will still apply, so I can do:

#show "CO2": [CO#sub[2]]
@breathing
#bibliography("bibfile.yml")

which will yield:

The issue is that now I need to check every citation for new show rules that I should add to my Typst source. In practice, I’m going to miss some of them and end up with poorly formatted references. Including all show rules needed for all references in my (potentially large) bibliography seems hacky and requires syncing data in two different files, never a pleasant prospect.

Is there a way to record this formatting information within the Hayagriva (or BibTeX) file?

Hey @Mathieu, welcome to the forum! I’ve changed your post’s title to a question in order to better fit our guidelines, feel free to adjust it further if needed: How to post in the Questions category

You can try using $math mode content$ in your bibliography file as that is usually preserved by Hayagriva. Otherwise, you’ll need show rules. Per-citation show rules are not currently possible, although there are some ongoing community efforts to make this possible.

1 Like

You could use eval and show rules to achieve this. For example,

bibfile.yml

title: Breathing in myeval(O#sub[2]) releases CO2

document.typ

@breathing

#show bibliography: it => {
  let reg = regex("myeval\((.*)\)")
  show reg: r => {
    eval(r.text.replace(reg, m => {
      m.captures.first()
    }), mode: "markup")
  }
  it
}

#bibliography("bibfile.yml")

yields this:

1 Like