Tempting Shortcuts
Working notes on the slower path

Notes > Tech > here

Notes on Bibtex and bibliography management

fixing tandfonline citation exports

When I export a citation (with references) from tandfonline.com, all of the references fail to have a citation key assigned and so it is an invalid bibtex file.

If you load it up in Vim (which you should have access to and be able to use) you can type the following one-liner to fix up the keys:

:%s/@article {,/=“@article{“.line(“.”).”,”/

Translated: ‘%’ whole file; ‘s///’ substitute (find and replace are between ‘/’ characters); ‘@article {,’ find this string; replace it with the next string, ‘line(“.”)’ means calculate the current line number

Citation keys

I write mostly in Scrivener and switched from using Multimarkdown as the output, to using pandoc. From there I generate LaTeX and my PDFs. I ran into an issue where the citation keys automatically generated by the bibliography tool that I use (Bibdesk) were not being parsed by pandoc in the TeX generation process. This seems to be by design in pandoc as it only allows ‘internal punctuation’. So I need to regenerate all my keys.

There is a discussion on StackExchange about ‘good practice’ for cite keys, and the only viable option is that which Google Scholar also uses #lastname#year#first_word_of_title. But that doesn’t cut it with titles beginning with ‘the’ for example.

My new/current key generation format is: %p2%Y%u1.%T3 which translates to 1 or 2 author or editor surnames (%p2), then publication year (%Y), a unique letter (like 1999a) (%u), a full stop, and then three 4 or more letter words from the title (%T3).

BibDesk Scripting

With a little Apple Scripting hooked into the BibDesk application, I’ve managed to generate slightly more verbose keys without the punctuation issue.

And the script is:

using terms from application "BibDesk"
  on perform BibDesk action with publications thePubs for script hook theScriptHook

    repeat with aPub in thePubs
        tell aPub
          set AppleScript's text item delimiters to {",", ":", ";", "--", ".-"}
          set currentValue to get cite key of aPub as text
          set newValue to text items of currentValue
          set AppleScript's text item delimiters to {""}
          set cite key of aPub to newValue as string
        end tell
      end try
    end repeat

  end perform BibDesk action with publications
end using terms from

Save that into ~/Library/Application Support/BibDesk/Scripts/

In BibDesk’s preferences, select ‘Script Hooks’ and then ‘Did Generate Cite Key’ and link it to the script. Done.

Misc notes