Last active
January 22, 2023 19:03
-
-
Save moritzpschwarz/1b42d687662ab63dd1ce206c35c8f038 to your computer and use it in GitHub Desktop.
When using biblatex, most citation styles do not retain capitalization of titles. This little R script reads in an existing bib file, changes the titles and then saves another bib file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read in the initial bib file | |
tex <- readLines("test.bib") | |
# get the location of the titles (NOTE: also will include fields of the nature 'booktitle') | |
title_loc <- grepl("title", tex, fixed = TRUE) | |
# Change the opening bracket from { to {{ | |
# the full regex looks for strings containing 'title = {,' or 'title={' and replaces it with 'title = {' | |
tex[title_loc] <- gsub("title = \\{|title=\\{","title = {{",tex[title_loc]) | |
# Change the closing bracket from } to }} | |
# the full regex looks for strings ending '},' or '} ,' and replaces it with '}},' | |
tex[title_loc] <- gsub("\\},$|\\} ,$","}},",tex[title_loc]) | |
# show result | |
tex | |
# write out the final adjusted file | |
writeLines(tex, con = "test1.bib") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment