# Advent of emacs #16: How I use the online LaTeX editor Overleaf in emacs

Posted on Dec 16, 2022 by Chung-hong Chan

If I could select, I won’t select $$\LaTeX$$ to write my papers. Usually, the decisions to write in $$\LaTeX$$ were not made by me, but my collaborators. I maintain that $$\LaTeX$$ should be an intermediate format. A target to be compiled to. But there are some situations one should (or must) write in $$\LaTeX$$. For example, if I am working with mathematicians or computer scientists.

But nowadays, researchers don’t like to write $$\LaTeX$$ on their own computer with their own text editor like in the 90s. Instead, they embrace the Google Docesque collaboration spirit and prefer the online editor Overleaf. Ten million users can’t be wrong. I wonder whether there are ten million active emacs users.

I am a bit allergic to online services. And I wished that I can edit my collaborators’ online $$\LaTeX$$ files in emacs. Of course, a straightforward solution is to use the Github integration function of Overleaf. But anyone who tries to use it to edit an everchanging article would know that this solution is suboptimal: The document online is everchanging, but you are working on a snapshot offline.

## GhostText

Edit With Emacs has been there since forever. The idea is to edit the text field in your browser with emacs. The idea is to start an editing server in emacs and then the browser, through a plugin, to activate the editing server and make the editing in emacs.

GhostText by Federico Brigante et al. is an improvement to this approach. GhostText supports multiple browsers and multiple editors 1. Also, the editing is in sync between the browser and the editor.

The browser end is relatively easy. Just install GhostText. I also wanted to take this opportunity to make an impossible appeal: Please use a browser that is not controlled by a big tech 2.

## Atomic chrome

The emacs end is handled by Atomic Chrome by alpha22jp et al. I recommend a tilting window manager (e.g. StumpWM). And the end result looks like this:

The idea is to trigger GhostText and that launches emacs automatically. The editing between the browser and emacs is now in sync. The nice thing about this is that I can even control which major mode to use. I have this in my configuration file.

(use-package atomic-chrome
:config
(atomic-chrome-start-server)
(setq atomic-chrome-buffer-open-style 'full)
(setq atomic-chrome-url-major-mode-alist
'(("github\\.com" . poly-markdown+r-mode)
("overleaf\\.com" . latex-mode)))
)


I can control atomic-chrome to use latex-mode for Overleaf.

# Bottom line

This method works for several sites. And I use it for Github and Overleaf. I would hope that this work for Google Docs, MS365, and even the so-called privacy aware Only Office. But unfortunately, GhostText doesn’t work for these sites. I won’t blame GhostText for this. Instead, it’s these platforms don’t use open standards.

1. This is usually a good thing to look for. It indicates the protocol is open. Also, many developers are on board.

2. I believe the deutschsprachiger Raum is a rare case where Firefox still has a double digit market share.

Powered by Jekyll and profdr theme, a fork of true minimal theme