Style the reference numbers in the bibliography in RC-0.14

I am maintaining a template that reproduces a LaTeX conference format, which manually changes the styling of the bibliography by removing brackets in the reference numbers (for instance, [1] → 1).

To reproduce that, I used undocumented internals, namely, I relied on the fact that the bibliography is a table whose first column contains the reference number in [1] format, and I then removed the brackets with a slice(). This is quick and dirty, and this may break in a future Typst release (especially when the bibliography switches from tables to outlines in the future), but I didn’t have many other options.

#show bibliography: it => {
  show grid.cell.where(x: 0): it => if sys.version == version(0, 14) {
    it.body
  } else {
    it.body.child.text.slice(1, -1)
  }
  
  it
}

@source
#bibliography(bytes("source:\n  type: article\n  title: FooBar"))

This hack was possible in 0.13.1 because the contents of the reference number were accessible in the bibliography table. However, in 0.14, the cells of the first column of the bibliography table contain a pdf-marker-tag() that, in turn, contains a direct-link(). However, it seems that the actual reference number inside this direct-link() element is inaccessible.

I still have the option of editing the bibliography CSL to remove the brackets, but this would mean that I can’t use the official CSL provided by Typst. Therefore, I still want to know if there is a way to edit the reference number in Typst.

You can apply a regex show rule on the reference number:

#show bibliography: it => {
  show grid.cell.where(x: 0): cell =>  {
    show regex("\[.*\]"): s =>  s.text.slice(1, -1)
    cell
  }
  it
}

but I’m confused by this part:

If you mean “can’t use the default style provided by Typst” that’s normal: if the conference uses a different style you should use the CSL for that style, anything else is a hack… If you mean that the CSL for the conference format doesn’t show the reference numbers correctly, that sounds like a bug in the CSL file, which could be fixed?

1 Like

Thanks for the trick. However I still find it strange that we cannot access the cell content anymore in 0.14.

That’s the thing. I’m reproducing the LIPIcs LaTeX format, that uses the plain.bst BibTeX style. This BibTeX style didn’t have a CSL version before I recoded it myself. However, LIPIcs doesn’t use the standard plain.bst format, as it removes the brackets in the reference numbers. So please don’t blame me, blame the LIPIcs publishers :sweat_smile:

Also, LIPIcs enforces a specific font and weight on the reference numbers, which cannot be specified in CSL.

Only certain styles of bibliography use a grid, some don’t use a grid. More details here: How to manually correct the format of bibliography (for ~60% styles)? - #4 by Y.D.X

1 Like

That’s interesting, thanks! Although I don’t think it will pose a problem in my case because I know which bibliography style I use, and thus if it’s a grid or not.

I have read on Discord that the long term plan is to implement bibliography with a outline instead. This would make more sense semantically, and this would allow users to style the bibliography way more cleanly (for instance we would customize reference numbers by changing the outline numbering), but this introduces efficiency issues. It would require too many passes of introspection, especially to resolve the size of the numbers AFAIK. To resolve that, we would need “local” introspection perfomed only on the bibliography outline (as opposed to “global” introspection on the whole document), which would involve profound changes to the core.