Tuesday, March 22, 2011

Oddly Specific

This is probably not going to be very helpful for the vast majority of my modest readership. But, I would like to put it out there on the internewts so that it can help some academics overcome a rather annoying problem with a literature search tool. Scopus doesn't export to BibTeX very well. And then when I try to keep my bibliography straight by using a tool called BibDesk, it explodes with complaints everywhere. I have put together this little sed script which gets rid of, for me at least, all thing errors and warnings in an exported scopus BibTeX bibliography.

#!/usr/bin/sed -f
# change comma separated author list to "and" separated
/^author/ {
s/[a-z] *\([a-z] *\)*,/ and /g
s/[a-z] *\([a-z] *\)*}/}/g
s/\([A-Z]\.\),/\1 and/g
}
# fix keys with accents and spaces in them
/@[A-Z][A-Z]*{/ {
s/[àáâãäå]/a/g
s/ç/c/g
s/[èéêë]/e/g
s/[ìíîï]/i/g
s/ñ/n/g
s/[òóôõöø]/o/g
s/[ùúûü]/u/g
s/[ýÿ]/y/g
s/[ź]/z/g
s/ //g
}
# fix quotation marks (there are other
# ways to do this, I just like this one)
s/"\([^"]*\)"/``\1''/g
# escape percent signs
s/%/\\%/g
# escape dollar signs (this could cause
# problems if there are math sections
# in abstracts or titles)
s/\$/\\\$/g

No comments: