Parsing BE BiBTeX export to enforce Case in Titles

Users asking other users for AppleScripts that work with Bookends.
Post Reply
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Parsing BE BiBTeX export to enforce Case in Titles

Post by iandol »

When BE automatically exports to BiBTeX using Applescript, abbreviations/acronyms like DNA whose case should be preserved are not wrapped with { }[1]. This means that, depending on the bibliography style you end up with Dna etc. I've made a little script in Ruby which edits the .bib file titles and simply wraps each of a list of acronyms with { }. I use this from naupaka's applescript exporter which I've modified to run this Ruby script, but you can run it by itself using fixCase.rb MyFile.bib:

fixCase.rb: https://gist.github.com/iandol/90684eee ... fixcase-rb

bookends_to_bibtex.scpt: https://gist.github.com/iandol/90684eee ... 6762d5149e

You need to put both bookends_to_bibtex.scpt and fixCase.rb on your path and the run it like so:

Code: Select all

> bookends_to_bibtex.scpt "My Group" /my/output/directory/ DEBUG
The DEBUG at the end simply gives you a little log of what was done, if you omit it, the script is silent (no output).

You need to edit fixCase.rb keepUpper and makeUpper lists with your own acronyms. I split this into two lists: keepUpper wraps {} only if the item is already the right case, whereas makeUpper enforces case even if the item is not the preferred case.

The script is pretty quick, it takes around 0.8s to process a 5MB bibtex file...

----
[1] I use Pandoc and CSL, however { } to protect case is valid in both CSL and BibLaTeX according to the Pandoc citeproc instructions.
Last edited by iandol on Wed May 24, 2017 1:01 am, edited 1 time in total.
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by Jon »

In BibTeX preferences there is this option:

Bracket acronyms in title, e.g. {DNA}

Did that not work for you?

Jon
Sonny Software
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by iandol »

Hi Jon, I'm using the Applescript method "set myBibTex to «event ToySGUID» thisList given «class RRTF»:"false", string:"bibtex"" to fetch the bibtex, and the titles are not {protected} with the settings in Prefs > Scan & Bib > Don't change case:...
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by iandol »

Hi Jon, I have also just tested manual export (File > Export References (Hits)... > BibTeX) and it doesn't seem to work. Now I naively assumed it would use the settings in "Sentence and Title Case" but rereading the manual and it is not clear, but it is not even bracketing acronyms the manual suggests it should, like 2D. Screenshot shows an export that contains 2D 3D and an entry in my Don't change case list, V4:
test.png
test.png (89.21 KiB) Viewed 17729 times
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by Jon »

It should bracket strings of uppercase letters. 2D works here. Make sure you have set the output encoding to BibTeX, not Styled Text or Plain Text.

Jon
Sonny Software
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by iandol »

OK I was using UTF-8. This is quite a confusing setting, as I can output RIS format using a BiBTeX "format", and the BiBTeX output is actually UTF-8 encoded! What is the BibTeX "encoding" actually doing that isn't just UTF-8 + the settings from Preferences? And although now {2D} is bracketed, all the entries on my don't change case list are not. It makes sense IMO to also bracket them.
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by Jon »

Output "as BibTeX" means that BibTeX markup will be used for styled text. This is independent of what format you're using (e.g. you could create a new format called My Format that is an edited version of the BibTeX format we supply, in which case you'd select BibTeX as the output markup. To make this more clear, in the next update I'll change the option in the Bibliography output dialog from "BibTeX" to "BibTeX Markup".

The "Bracket acronyms in title" setting in preferences has nothing to do with your "don't change case" list. It does what it says -- puts curly brackets around stretches of upper case acronyms. The "don't change case" list is only used when the format calls for the title field to be output in a special case (e.g. Title Case) and you want to preserve acronyms. It will have no effect if the title is output as entered (which is how the BibTeX format is set up).

Jon
Sonny Software
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by iandol »

OK so the fix case script still offers some useful functionality (more general in what can be protected, and preserve+enforce lists) not available within the bookends export...
Dellu
Posts: 268
Joined: Sun Mar 27, 2016 5:30 am

Re: Parsing BE BiBTeX export to enforce Case in Titles

Post by Dellu »

Jon wrote: Wed May 24, 2017 11:33 am The "Bracket acronyms in title" setting in preferences has nothing to do with your "don't change case" list. It does what it says -- puts curly brackets around stretches of upper case acronyms. The "don't change case" list is only used when the format calls for the title field to be output in a special case (e.g. Title Case) and you want to preserve acronyms. It will have no effect if the title is output as entered (which is how the BibTeX format is set up).

Jon
Sonny Software
I wish there is a way to customize the acronym list. I was also thinking the "don't change case" list is used for the same purpose.
I want the number of words to be exported as they are (under the braces) so that bibtex will not convert them to lower case.
Post Reply