I have a CV that renders the full contents of a bibtex .bib file containing my publications. I would like my CV to update a description counting the number of publications in each journal every time add an entry to the .bib file. How can I count the number of publications in different journals automatically?
#let journal_name = "Physical Review Letters"
// How do a make the hypothetical function that counts papers?
#let number_PRL = count_pubs("papers.bib", #journal_name)
I have written #let number_PRL papers in #journal_name
#bibliography("papers.bib", full: true)
Hmm, here is a fragile hack that uses regex to parse raw ref.bib. It should work if your ref.bib is properly formatted. (at least I think so)
#let journals = {
read("papers.bib").matches(
// Assuming you always use `journaltitle` but never `journal`,
// and no journal title contains any bracket
regex(`\s*journaltitle\s*=\s*\{(.+?)\},`.text)
).map(it => it.captures.at(0))
}
#let count-journal(journal) = {
// Assuming you always use “Physical Review Letters” but never “Phys. Rev. Lett.” or “PRL”.
journals.filter(j => j == journal).len()
}
#count-journal("Physical Review Letters")