How to add tracking (letterspacing) to author names in bibliography?

Hi all,

I am using a bibliography style that requires author names to be typed in small caps. See the following example generated in LaTeX:

I got a CSL file for this specific citation format, and I see it uses the font-variant=“small-caps” parameter for author values, which seems to be correctly read and rendered by Typst. However, I want to add tracking (letterspacing) to the small caps in order to improve readability. I have been adding tracking with success in other parts of my document for text in all caps and small caps.

For small caps in specific, I used this:

#show smallcaps: set text(tracking: letterspacing)

It works when I manually use smallcaps throughout the document, but does not affect the text in the bibliography. Since Typst is actually rendering the small caps for author names in the bibliography, I wonder why it is ignoring the show-rule.

An example of what I am getting in Typst (I still have to do some fixes to the CSL file, so ignore the poor formatting):

You can see that the small caps are correct, but it is ignoring the tracking. However, it works if I apply it globally with a set-rule, but in this case, it affects other parts of the bibliography entries.

Does anyone know a workaround or a way to troubleshoot the bibliography generation by Typst?

Thank you in advance!

I think this might work, if you want to target specifically smallcaps that is inside of bibliography

#show bibliography: it => {
  show smallcaps: set text(tracking: letterspacing)
  it
}

If you’re fine with changing tracking on entire bibliography:

#show bibliography: set text(tracking: letterspacing)

sadly that doesn’t work because, internally, the bibliography element doesn’t delegate to the smallcaps element (which would get matched by that rule), but rather “hardcodes” the small-capped style into a regular piece of text (source).

making bibliography use text formatting elements directly seems like a reasonable (and interesting) feature request to make.

Sorry @sermuns, as I mentioned, I used the show-rule for the smallcaps element:

#show smallcaps: set text(tracking: letterspacing)

This is a generalization of what you suggests. However, as @cAtte mentioned, it seems that small caps style in the bibliography element is not created by the smallcaps element.

@cAtte, if I correctly understand the source code you cite, the small caps in the bibliography are directly typesetted with the font’s small caps variant. Indeed, the smallcaps element isn’t use there.

For anyone interested, my hacky workaround was changing the CSL style to add the raw strings NAME_START and NAME_END as prefix and suffix for the author name variable. Then, in Typst, I use regex replacement rules to remove those custom tags and apply smallcaps to any text between them. Somthing like the following.

In CSL:

<names variable="author" prefix="NAME_START" suffix="NAME_END">
  <name delimiter="; " initialize-with="." name-as-sort-order="all" />
</names>

In Typst:

#show smallcaps: set text(tracking: letterspacing)

#show bibliography: it => {
  // Hack to add letterspacing to names
  show regex("NAME_START.*?NAME_END"): it => {
    show "NAME_START": none
    show "NAME_END": none
    smallcaps[#lower(it)]
  }
  it
}
3 Likes

check out issue #6639: Delegate styles to text formatting elements in bibliography (as in, if it ever gets closed you can get rid of your hack)

2 Likes