I have a big BibTeX file with entries with keys such as smith-jones-2011 and shah-2018. I'd like to rename these keys into Smith2011 and Shah2018 instead but I don't want to break the LaTeX files that refer to the old keys. Is there a good automated way to change all of the keys in the BibTeX file and updating the LaTeX files?
-
Start a new database for new documents. – Johannes_B Jun 14 '18 at 16:13
-
As the .bib and tex files are both plain text, just use a tool for search & replace in several files. There are many. If you are a Linux user, for example, a good option could be rpl. – Fran Jun 14 '18 at 17:25
-
2Related: https://tex.stackexchange.com/a/5256, https://tex.stackexchange.com/a/417917 – Marijn Jun 14 '18 at 20:51
1 Answers
.bib files have no knowledge about the .tex documents they are used in, so a .bib file can't magically go back through all your files and change the citation keys.
A simple search-and-replace job across all your .tex might be enough for you. If your database is big you may want to try and automate this by obtaining a list of old and new keys that can be worked through one-by-one.
If you are using biblatex (with Biber) you could use the ids field to keep the old name alive. See kregkob's answer to bibtex with multiple aliases for the same reference and also PLK's answer to Having several keys refer to the same bibliography entry
@article{Smith2011,
ids = {smith-jones-2011},% <- old key
author = {Jane Smith and Emma Jones},
title = {Title},
journal = {Journal of Stuff},
year = {2011},
volume = {12},
}
A bit of a hack would be to crossref the old name to the new one
@article{Smith2011,
author = {Jane Smith and Emma Jones},
title = {Title},
journal = {Journal of Stuff},
year = {2011},
volume = {12},
}
@article{smith-jones-2011,
crossref = {Smith2011}
}
as suggested by frabjous in Can a bibtex entry be given more than one reference name?. This need not work with all .bst files and can lead to duplication in the bibliography and other weird side-effects if both names are used in the same document.
If you are exclusively using biblatex (with Biber) you should be fine with ids. Otherwise I would suggest the search and replace solution.
- 175,683