How to underline specific bibliography entries?

I would like to underline specific entries in my bibliography depending on the key used to cite them. Please can you help me how to do this?

I think the code should look something like this:

This citations @Me2023 is underlined this other citations @someoneelse2024 is not.

#show selector(bibliography).or(cite): it => {
  if "Me" in it.key {
    underline(it)
  }
  it
}

#bibliography("refs.bib", style: "american-physics-society")

How can I get responses to this question?

You give an example of how you think it should work in your original post. Does this work at all? Have you actually tried it? Does it do something unexpected?

The code in your original post is not formatted, this makes it much less pleasant and slower to read. You can use format it like this:

```typ
//your code here
```

General recommendations from the FAQ:

Unfortunately for your actual question I don’t know much about citations or using a bibliography file and don’t have any such files around to test with.

2 Likes

The following code I wrote only applies to citations. Bibliography entries cannot be edited in the current version, but might be possible in the future ( Add bibliography.entry element by xkevio · Pull Request #5932 · typst/typst · GitHub).

#show cite: it => {
  if "sandby" in str(it.key) {
    underline(it, offset: 0.2em)
  } else {
    it
  }
}

The following citation should be underline @sandby_cost-efficient_2021 and the other one @niu_underwater_2022 not!

#bibliography("test.bib", style: "american-psychological-association")

May I ask, why exactly you want to stylize specific entries/citations?

You can do some hacky editing with show rules but it’s not great, especially where the entry is styled in parts:

#let bib = ```
@article{niu_underwater_2022,
  title={Underwater wireless charging system of unmanned surface vehicles with high power, large misalignment tolerance and light weight: Analysis, design and optimization},
  author={Niu, Songyan and Zhao, Qingyu and Chen, Haibiao and Yu, Hang and Niu, Shuangxia and Jian, Linni},
  journal={Energies},
  volume={15},
  number={24},
  pages={9529},
  year={2022},
  publisher={MDPI}
}
@article{sandby_cost-efficient_2021,
  title={A cost-efficient low-weight autonomous profiler for measurements in polar coastal waters and other regions with strong density gradients},
  author={Sandby, Lucas M and Mejdahl, Jens EB and Bjerregaard, Simon H and Melvad, Claus and Rysgaard, S{\o}ren},
  journal={HardwareX},
  volume={10},
  pages={e00207},
  year={2021},
  publisher={Elsevier}
}

```.text


The bibliography entry for @sandby_cost-efficient_2021 should be underlined and the other one @niu_underwater_2022 not!

#show regex("L. M. Sandby.*gradients,”"): underline

#bibliography(bytes(bib))

Here the regex cannot match the italic part so I stop it before the whitespace before HardwareX.

Yeah, so as @Electron_Wizard mentioned, when Add `bibliography.entry` element by xkevio · Pull Request #5932 · typst/typst · GitHub is ready and merged, you can just do:

#show bibliography.entry.where(key: <your-label>): underline
1 Like

I would like to underline papers written by me. The PR looks promising, thank you for referring to it, but it will not work now and it is not clear whether it will definitely be merged?

Since you earlier asked why this post wasn’t getting much traction I though I would point this out, it could help you get more responses (on this post and future ones):

This is ends in a question mark but is not a question:

Is there something specific you want to know? Or are you simply looking for confirmation that there is no fixed release date?

1 Like

Hi @Mark_Dean, I have formatted the code in your post. you can press the :pencil2: pencil icon at the top to see the changes (select “Raw” to see what I actually wrote in the post’s text field). Making your post more readable using the tips @gezepi provided (code formatting, clearly state questions, following the guidelines) usually helps with engagement. Apart from that I want to mention that stating what errors your code produces also helps.

You’d have to check, but maybe my package Alexandria can help here: it lets you get a list of references before rendering it, maybe you can use that to underline some entries (although I’m honestly not sure about it).

Finally, if you feel the response you got has sufficiently answered your question, be sure to give it a checkmark :ballot_box_with_check:. This will help others find the solution in the future. Thanks!

Thank you. I will look into your package.