≡ Menu

Using Dropbox and Git to write LaTeX papers

First things first — Dropbox is awesome. (Also, if you signup through that link, we both get extra free space… so do it). It’s a service that syncs a folder on your computer with a central server — and any other computers you have Dropbox installed on. But it does much more than that — you can share subfolders with other Dropbox users. For example, if I want to give my roommate a directory full of PDFs, I can just drag the directory into our shared folder, and Dropbox will automatically sync it so that he gets all the files without doing anything. Also, the files are on your computer — so if you lose internet or are on an airplane, you interact w/ the files just like any others on your computer.

Writing anything with LaTeX can be a trying experience. Writing an academic paper with multiple authors in LaTeX can be especially tricky. Dropbox comes in handy — but so does being able to use version control to track who changed what and when. Since Dropbox syncs files (and keeps a record of how the file looked in the past) it can sorta do the version control thing on its own.

Let’s just say you have the desire to use git (the fast version control system).

EDIT 1: Hannes (comment below) has warned that this is probably a bad way of doing these things.

Instead of Dropbox, use something like github to sync git repositories.

One trick I’ve found handy is to write LaTeX papers with each sentence on a new line — rather than putting returns on some number of characters. This way, diff and version control finds changes between sentences instead of just lines, which makes everything much easier to understand.

EDIT 2: Lelio (comment below) has suggested that this trick is unnecessary, instead use: git diff –word-diff. I haven’t tried it yet, but it seems reasonable enough to mention in the post itself.

I wanted for git to ignore a number of the helper files that get created when compiling LaTeX and found a useful repository of gitignore flags here. (Read the gitignore manual page here).

Easy enough to setup — I put it in my home directory, so keep that in mind if you put it somewhere else — so I did the following:

cd 
git clone git://github.com/github/gitignore.git

Now, I was actually confused about what to do at this point. After playing around with it for a while, I ended up making a bash script that keeps the git-ignore repository updated and referenced for my laptop. You can find the bash script here.

bash ~/Dropbox/scripts/git/gitignore.bash

Assuming you have my bash script in that location, that should create the .gitignore in your home directory. Next, you have to tell git that you want it to use the .gitignore file that the bash script created at ~/.gitignore for everything.

git config --global core.excludesfile ~/.gitignore

Here’s how I have cobbled together how I work with

On my laptop:

cd ~/Dropbox/Writing/
mkdir New-Project.git
cd New-Project.git
git --bare init
cd Project/location
git init
git add .
git status
git commit -m "First commit"
git remote add dropbox ~/Dropbox/Papers/2011-02-17-Whitmore-KeckCalibration.git
git push dropbox master

On another computer with a Dropbox account:

cd 
mkdir Papers; cd Papers/
git clone -o dropbox ~/Dropbox/Papers/2011-02-17-Whitmore-KeckCalibration.git

change some file

git commit -a 
  "First other computer edit"
git push dropbox master

Back on my laptop:

git pull dropbox master

work work work

git push dropbox master

Back on other computer the destination isn’t required:

git pull

work work work

git push

That should do it. If you have a better way of accomplishing the same thing, please let me know, I’m always on the lookout for doing things the right way.

Comments on this entry are closed.

  • Hannes 2011-04-07, 09:49

    I'm sorry to spoil the party, but what you're doing puts you in extreme danger of corrupting your repository. Dropbox is not a central server, so there is always a delay between when you're writing to your local copy of the repository and that change is uploaded to the Dropbox servers and downloaded to any other machines. If several people are pushing to the repository in a short time interval from different machines, then you risk to totally corrupt your repository. This may not be a great danger if you're working alone, but someone may read this and think they'll set up a git repository on Dropbox for their whole group. Better don't do it! git was not built with anything like Dropbox in mind. Putting your repositories on there is a hack which may work out for a while but where unexpected things may happen. Instead, get a proper webspace if you want to host yourself or go with github.

    • Lelio 2012-05-26, 07:38

      Also, I see, you are writing each sentence on its own line, because of some of your dumb and obsolete diff tool… for God's sake, people, learn about git diff –word-diff instead of line-comparing! Also, the emacs's ediff option "ediff-windows-wordwise" is doing similarly for a diff decent diff tool