BibTex export - protect capitalisation

A place for users to ask each other questions, make suggestions, and discuss Bookends.
Post Reply
pharaoh
Posts: 22
Joined: Tue Dec 08, 2009 5:09 am

BibTex export - protect capitalisation

Post by pharaoh » Tue Mar 10, 2020 7:40 pm

Dear forum members,
I have talked to Jon about it, and he could not find a solution about it.

I am using Pandoc citation format, so I export my Bookend file as BibTex. Many of my titles have place names (Bangkok, Thailand, Angkor Wat etc) or royal names (Thutmose III, Tutankhamun, Akhenaten). I would like that those names are protected (i.e. surrounded by curly brackets) at the time of the export, otherwise I have to correct them by hand in JabRef.

Can you advise about any procedure/tool I can use in order to avoid to correct after export?

If so, can you explain it to the list step by step, also for future reference for other users.

Rob

kseggleton
Posts: 29
Joined: Fri Jan 01, 2016 6:47 am

Re: BibTex export - protect capitalisation

Post by kseggleton » Wed Mar 11, 2020 3:56 am

See this topic on how to protect capitalisation with Bibtex: https://www.sonnysoftware.com/phpBB3/v ... f=6&t=4044

iandol
Posts: 302
Joined: Fri Jan 25, 2008 2:31 pm

Re: BibTex export - protect capitalisation

Post by iandol » Thu Mar 12, 2020 7:51 am

For the script I shared (https://github.com/iandol/dotfiles/blob ... fixCase.rb) it should be fairly easy to turn this into a droplet with something like Platypus if you are scared of the command line, though I run it as part of a mostly automated script that exports to BibTeX, converts that to JSON (which is much faster when running Pandoc), runs fixCase.rb, minifies the JSON and moves it to Dropbox to sync across my computers.

pharaoh
Posts: 22
Joined: Tue Dec 08, 2009 5:09 am

Re: BibTex export - protect capitalisation

Post by pharaoh » Mon Mar 16, 2020 4:14 am

Dear Iandol,
as the moment I am using your BookendstoBibtex script automation in Alfred, with the option to protect the titles. I can use even the script, which I believe I would use from the terminal nonetheless, but I am a bit over some deadlines, so I keep it simple with the Alfred automation.

As you said that you created a script moving from Bookends to JSON, is it possible to share the script with the forum members, and the procedures to run it. Due to the current pandemic, I have some time toward the end of this month.

Thanks,

Rob

iandol
Posts: 302
Joined: Fri Jan 25, 2008 2:31 pm

Re: BibTex export - protect capitalisation

Post by iandol » Wed Mar 18, 2020 7:37 pm

Yes my script rather simple, and you'll need to change paths and filenames to fit your needs. I initially export the BibTeX file to my desktop and the source file is always called Core.bib, the script takes that file and does the rest:

Code: Select all

#!/usr/bin/env zsh

printf "\n---> Processing Bibliography file @ \e[93m$(date)\e[m...\n"
cd ~/Desktop

printf '\n---> Citeproc generating JSON from BIB file...\n'
pandoc-citeproc -j ~/Desktop/Core.bib > ~/Desktop/Temp.json

printf '\n---> Processing title case...\n'
fixCase.rb ~/Desktop/Core.bib
fixCase.rb ~/Desktop/Temp.json

printf '\n---> Minifying JSON...\n'
jq -c . < Temp.json > Core.json

printf '\n---> Moving to Dropbox...\n'
mv ~/Desktop/Core.* ~/Dropbox/Papers/References
rm ~/Desktop/Temp.json

printf '\n---> ...Finished!\n'
You need to save this as a file, called e.g. processbib.sh, and change the permissions to be executable:

chmod +x processbib.sh

So my updated Core.bib and Core.json files are now physically in my Dropbox, and personally I soft link them into my Pandoc data directory so Pandoc uses them without needing an absolute path, but you can just give it an absolute path.

pharaoh
Posts: 22
Joined: Tue Dec 08, 2009 5:09 am

Re: BibTex export - protect capitalisation

Post by pharaoh » Sun Mar 22, 2020 10:56 am

Dear Iandol,
I tried to run the script below, but it complained that fixcase.rb could not be found. I also tried to create an application with Platypus, but I did not see working either. May I ask you where the script below and Fixcase.rb should be saved in order to make the script running?

Thanks,

Rob

iandol
Posts: 302
Joined: Fri Jan 25, 2008 2:31 pm

Re: BibTex export - protect capitalisation

Post by iandol » Tue Mar 24, 2020 10:34 am

Scripts need to be in your path, or you must run them from the current directory. I create a folder called bin in my home directory, ~/bin, and put all my scripts there, but by default this is not part of the default path, so I add it to my path by editing my .zshrc startup file (I use zsh, which is slightly different to bash, and now the standard shell from Catalina onwards).

In my .zshrc:

Code: Select all

[[ -d "$HOME/bin" ]] && path=("$HOME/bin" $path)
export PATH
For bash you need to do something like this in .bashrc or .bash_profile:

Code: Select all

export PATH=$HOME/bin:$PATH
But if you don't want to fuss with modifying your path, you can run using the ./ prefix which means "current path", so if you saved a script like fixcase.rb to your Downloads folder you could do the following:

Code: Select all

cd ~/Downloads
chmod +x fixcase.rb
./fixcase.rb
I made a Platypus app, it will ask for a file or you can drop a file on it, not sure if it will work for you as it's ages since I used Platypus (note this contains just the fixcase.rb script, not one one that does the other actions as that needs editing by each user to set their names and preferences):

https://www.dropbox.com/s/vufxh7w11fb7o ... pp.7z?dl=0

Post Reply