Writing your dissertation (or book!) with Overleaf + git

In many technical fields, a PhD dissertation is written with the mantra “staple 3” – take three peer-reviewed articles, add an introduction and conclusion, and turn it in. In writing my dissertation, I used LaTeX in Overleaf and git to make it easy to reuse content from articles.  Using this modular approach meant that I could edit the dissertation offline in TexStudio when traveling, integrate edits from committee members on Overleaf, and have version control with Git.

Notes:

  • If you aren’t familiar with using git, you can ignore those components, and just take advantage of the modular approach to structuring your dissertation.
  • If you don’t like Overleaf, you can do this on your own computer, and optionally back up with Github!

Steps:

  1. Set up each article as an Overleaf repository (if you haven’t done so already) and save a .zip file with the published state of your articles.
  2. Separate each article into article-specific content, and generalized content which you’d like to reuse in the dissertation/book.
  3. Create your dissertation locally, and pull in article-specific content into each chapter
  4. Clone each article into subdirectories of your dissertation, and set the chapters up as fake git submodules
  5. Add transitions; Push the dissertation to Overleaf
  6. Normal git pull/edit/push iteration for integrating feedback
  7. Graduate!

The finished product is viewable here on Overleaf, where you can download a .zip file for the whole project which you can then upload to your own Overleaf account.  You can also see the files for the whole dissertation on Github here. If you just want the tex files for the blank dissertation, you can get a zip version of the dissertation template here.

1. Set up articles as Overleaf repositories

Overleaf is a great tool for collaboratively editing LaTeX projects, and each Overleaf project has a built-in git repository available in the ‘Share’ button. Pretty cool, eh?  Check out the Overleaf tutorial if you’re unfamiliar, and upload your existing LaTeX files.

Here are two sample articles, one sample article with the Elsevier review formatting used by Applied Energy, and one sample article with IEEE conference formatting.

2. Separate each article into article-specific content, and generalized content

In each of the articles above, I’ve separated the body of the article into content.tex, which is \input into root.tex.  Root.tex includes the abstract, conclusion, bibliography, packages, and context-specific formatting. If you’re presenting the work at different venues, you could also have a number of different files in the style of root.tex, each for the different venue.

If there is venue-specific formatting or content within content.tex, this can be toggled by defining a conditional, such as \newif\ifarticle \articletrue in the preamble. Use this to trigger a switch in your content, like \ifarticle{ a } \else { b } \fi.

3. Create your dissertation locally

I’m using the UC Berkeley dissertation template, which is similar to that used by most engineering programs. The repository associated with this has a blank version as a zip file.

Because Overleaf doesn’t accept a number of file types, make sure to set up a .gitignore file as soon as you create the project, and before your first commit!

Once you’ve set up your .gitignore, initialize the folder as a repository:

$ git init
$ git add .
$ git commit -m "First commit, no chapter-specific content"

4. Clone articles in to subdirectories and set up as fake submodules

We want to be able to manage versions of each article, while also managing changes to the overall dissertation. To do this, we’d like to have a git repository for each chapter, inside of the dissertation repository. However, Overleaf doesn’t have a full git bridge, making conventional submodules impossible- this is a workaround! (as of May 20, 2018).

To add the chapters as ‘fake’ submodules, we’ll clone them into their destination in the dissertation folder, then add them as a fake submodule by including a trailing slash in the folder name.

Be sure you’ve set up a .gitignore file in your dissertation and each of your chapter-specific repositories before doing this!

$ git clone https://git.overleaf.com/16495485mzqgvcsdfdsa chapters/background
$ git clone https://git.overleaf.com/16223432asdfdsasdfre chapters/blockchains
$ git add chapters/background/
$ git add chapters/blockchains/

5. Add transitions; Push the dissertation to Overleaf

Your dissertation should compile locally, with all the chapters included. Add transition material to make the chapters flow smoothly together, then git commit and git push the dissertation to Overleaf for review by your committee and collaborators.

 

Editing and integrating updates:

There are now 3 ways that your content can be changed, making it tricky to avoid conflicts:

  1. Change content locally
  2. Change in Overleaf article project
  3. Change in Overleaf dissertation project

To avoid merge conflicts, it’s important to keep this in mind, and use git pull to integrate edits from Overleaf before making local edits. I tried to just make local edits, work with branches whenever I was expecting faculty feedback, and when working on Overleaf I preferred to make chapter-specific edits in the corresponding article projects.

Conclusion

I’m sure there are more elegant ways to do this, and more complex ways to do this, and more complex ways to do this more elegantly – this happens to be my implementation. Enjoy, and happy graduation season!

Leave a Reply

Your email address will not be published.