How to use a single .bib file with multiple ShareLateX projects

I’ve been using ShareLateX, which lets you edit your .tex documents collaboratively online, for years now. I’m happy with it, except one thing: you have to have a different bibliography file per project. In this post I explain a workaround I created for this problem. It’s not beautiful and requires that you use Windows and have ShareLateX premium, but if you have a similar problem, read on!

A better workflow

If you are like me, you generally “manage” your bibliography by the following method:

  • Copy-paste .bib file from a recent project
  • Copy-paste new references from Google scholar while writing
  • Clean up all the missing fields etc, when paper is ready for submission
  • Forget you did this, and do this all over again for the next project

Sure, it’s possible to have a single master bibliography offline, and then every time you add a reference, to export the bibliography, and import it in your current projects. But this is a bit time-consuming, so I decided to find a way to automate the process a little bit. There are four steps to this:

  1. Create a clean master bibliography in Dropbox
  2. Enable syncing between ShareLateX and Dropbox
  3. Set up script to copy master bibliography to ShareLateX folders
  4. Schedule the script

Master bibliography with Jabref

The first step to a better system is to actually have a cleaned up bibliography file that you will WANT to use. I do this in Jabref, because it is as close to “just editing .bib files” as I can get, has everything I need, and is free/open source.

To finally create a single bibliography, I copy pasted the bibliographies from my MSc thesis, my PhD thesis and my papers since my PhD into a giant .bib file. This created lots of duplicates, but these can be edited in Jabref. This was quite neat, since it allowed to me to choose the “most cleaned up” version of the reference. This was a time-consuming process, but hopefully with this system I don’t have to go through it again. My master bibliography now lives in a Dropbox folder called “Bibtex”.

 

ShareLateX – Dropbox sync

The next thing that I needed is syncing between Dropbox and ShareLateX. Unfortunately this is a premium feature at this time.

If you have the syncing enabled, each paper lives in its own Dropbox folder, under Dropbox/Apps/ShareLatex. Here are mine:

Each of these folders has a .bib file. Although locally I could ensure that the projects link to my main bibliography file in Dropbox/Bibtex, I cannot do this in the cloud.  (Or, there is a way to do this but I haven’t found it, which would render this blog post obsolete).

 

Copy bibliography to project folders with a script

My “genius” solution is to copy my master bibliography to the individual project folders. Of course I don’t want to do this manually – I want an “if this then that” solution that does it for me when the bibliography is updated.

In the end I settled for a slightly simpler solution of “copy every hour between 8 and 17” (when I’m most likely to be writing). Not as elegant, but (at least in Windows) it’s the 20% of effort that gives me 80% of results.

To copy files automatically, I used a Powershell script that says what to copy and where, and the TaskScheduler, which actually runs the script.

The Powershell script is called jobBibtex.ps1 and has the following contents (you can just create it with Notepad, but be sure to save it as “other” and not as a text file):


$SourcePath = "C:\Users\Veronika\Dropbox\Bibtex\refs_main.bib"
$DestinationPath1 = "C:\Users\Veronika\Dropbox\Apps\ShareLaTeX\Crowd2018"
$DestinationPath2 = "C:\Users\Veronika\Dropbox\Apps\ShareLaTeX\Survey2018"

Copy-Item –Path $SourcePath –Destination $DestinationPath1 -Recurse
Copy-Item –Path $SourcePath –Destination $DestinationPath2 -Recurse

The script now has hard-coded in it which projects it should copy to. A better version would go through all the folders in Dropbox/Apps/ShareLatex – this is the next improvement on my list.

Schedule the copying script

The last thing is to schedule the copying script. I used this tutorial to get this done, but here is a short summary. From the start menu, search for the TaskScheduler program. Once there, go to “Actions” and “Create basic task”

 

In the menu that comes up next, you need to select a name for your task (“Copy bibliograhy”) and select a trigger, for example “Daily at 8AM”. As the action, select “start a program”.

The program that you are starting is Powershell.exe, and you need to add the following argument (replace the path with wherever you saved your .ps1 script:


-ExecutionPolicy Bypass C:\Users\Veronika\Dropbox\Scripts\jobBibtex.ps1

Save the task and run it to see if your .bib files were really copied!

80/20 rule

Clearly this is not a perfect solution.

  • This is a one-way sync, so editing a copied .bib file on ShareLateX will not reflect in your master bibliography. This is problematic for collaborative projects. My solution would be to have two .bib files in each project – one with the master bibliography, one with additional files your collaborators want to add (which you could later add to the master .bib file).
  • The projects which to copy to are now hard-coded in the script – it would be better if if the script would work for any new folders in Dropbox/Apps/ShareLateX
  • Copying every hour is too much, a “when updated” copy would be more neat

But, it is the 20% solution that gives me 80% of the results I wanted, and hopefully will save me time in the future.

 

Do you have similar solutions in place? Leave a comment below!

Leave a Reply