Turning over a new leaf

Overleaf, formerly known as Share$\LaTeX$, is the go-to collaborative document editor for many researchers, who have taken advantage of its free tier. It’s a web-based editor that compiles $\LaTeX$ documents in real time, with several word-processor-like features like commenting, tracked changes and a GUI. However, the company has made collaboration a paid feature, meaning you either need to pay for a premium membership or find an alternative if you want to continue editing academic papers with your colleagues in real time.

Despite having enjoyed access to an institutional subscription to Overleaf Premium for some time, I find this a great opportunity to explore alternatives.

Collaborative Markdown editing

If you have read other posts on this blog, you’ll be aware that I am a fan of literate programming using Markdown. This blog, many of my papers and my PhD thesis are all written in R Markdown, which integrates text and generation of plots and tables for truly reproducible writing. Quarto, R Markdown’s less R-centric spiritual successor, integrates a few popular extensions to provide better native support for things like equation cross-referencing and writing books.

One of the biggest weaknesses of (R) Markdown is its lack of a simple collaborative editing feature to rival Overleaf. Although Overleaf does support knitr, you still have to write in $\LaTeX$ syntax, which is less intuitive than Markdown and offers fewer output formats. Some niche solutions exist, such as trackdown, which lets you do tracked changes via Google Drive, RStudio Posit Cloud, which has a free tier allowing one shared space with up to five collaborators, and one or two experimental online R Markdown editors that I can no longer find.

Knitr in Overleaf

The ‘proper’ solution is of course to use a shared Git repository, but although this is apparently even how Overleaf works behind the scenes, it’s not quite as instant or accessible as editing a Word or Overleaf document online, and it doesn’t run your code or render the output automatically.

Visual Studio Code Live Share

However, Visual Studio Code has a few handy features that makes it a promising alternative. As well as being able to edit files on WSL and on remote servers, there are countless extensions for linting R code, highlighting columns in CSV files and AI integration with GitHub Copilot. Obviously you can therefore write your R Markdown and Quarto documents in VS Code, just as you might have done using RStudio. But the real killer feature is the Live Share extension, which lets you share a workspace with others, who can edit the same files in real time, with syntax highlighting and code completion.

Visual Studio Live Share

This means collaborators can edit the same document in real time, with one author hosting the live session and nobody else needing to install all the same dependencies or have access to datasets on their own machines. When the host saves the document at the end of the session, it can then be committed to Git or your shared repository as normal, without conflicts. And rather than the Google Docs and Overleaf chat functions, which I don’t believe anybody on the history of this Earth has ever used, you can communicate using your usual medium, be it Teams, Slack, WhatsApp etc.

GitHub Actions

The obvious limitation here is that at least one user has to be hosting a Live Share session from a computer with all relevant dependencies for rendering the document. The other half of the solution is GitHub Actions (or your favourite equivalent continuous integration tool). On committing to your repository, a script will run on a virtual machine to compile the document and save the results as an ‘artifact’. This can then be downloaded like a software release or committed back into a branch of the repository. It is not quite instantaneous, and can require a bit a TLC to keep it running, but means you can edit text and commit from anywhere.

Quarto provides several GitHub Actions for rendering and publishing projects, and the same are available for R Markdown.

Putting it all together

Coming soon: along with a bonus post on reproducible collaborative poster presentations.