Home


Best way to write LaTeX

01 Nov 2024

Over the last couple of years I struggled choosing the best program to write latex. Most of academics prefer overleaf, but it just don't feel right to spend too much time working in browser. At the end of the day, browser was created to waste time, not to write research papers. I get it, everything is a web app today. But even if I ignore the ethical problems with that, there are tons of feature that overleaf lacks and got forbid you have a shitty internet connection.

So, what other options do we have? Not much to be honest, if we forget about old pre-web programs that nobody cares to use or maintain these days. Ok, but writing latex is just like writing text, or writing code ... So, what about a code editor? Besides, it would be great to edit your scripts for plots and paper in the same environment. Right? What is the most popular code editor these days? VS Code, no thanks. It is basically another web app, that feels extremely slow and has "highly-trusted" Microsoft badge on it. Preferably I should have access to the source code, so I can modify it to my needs. Then we are left with two good old options: vim and emacs.

I don't want to start a war here. You can go really go with either one. I am long time vim user, but this time I settled on emacs. Below are my versions of the setup for vim and emacs. I include the configurations for for Linux with Zathura as PDF reader. You can do the same easily on Windows with Sumatra PDF or Mac with Skim.

If you prefer vim, first install VimTex plugin. Then add the following to your .vimrc


let maplocalleader = ","
let g:vimtex_view_method = 'zathura'
let g:vimtex_quickfix_open_on_warning = 0
let g:vimtex_view_skim_activate = 1
nnoremap  :VimtexView
	

Install and configure AUCTEX plugin if you settled:


(add-hook 'LaTeX-mode-hook #'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'my-latex-auto-compile-and-view)
(add-hook 'LaTeX-mode-hook #'flyspell-mode)

(use-package auctex
	:ensure t
	:defer t
	:mode ("\\.tex\\'" . LaTeX-mode)
	:init (progn
		(setq TeX-auto-save t)
		(setq TeX-parse-self t)
		(setq-default TeX-master nil)
		(setq font-latex-fontify-script nil)
		(setq TeX-source-correlate-mode t)
		(setq TeX-source-correlate-method 'synctex)
		(setq TeX-source-correlate-start-server t)
		(setq TeX-view-program-selection '((output-pdf "Zathura")))
		(setq TeX-view-program-list
		      '(("Zathura" "zathura --synctex-forward %n:%c:%b %o")))
		)
	)

(setq ispell-program-name "aspell")
(setq ispell-dictionary "british")
(eval-after-load "flyspell"
  '(progn
     (define-key flyspell-mouse-map [down-mouse-3] #'flyspell-correct-word)
     (define-key flyspell-mouse-map [mouse-3] #'undefined)))
(add-hook 'LaTeX-mode-hook
          (lambda ()
            (electric-indent-local-mode -1)))


(defun my-latex-auto-compile-and-view ()
  (add-hook 'after-save-hook
            (lambda ()
              (TeX-command-run-all nil))
            nil t))
	
You can change your settings there, but that is what works well for me. Whenever I save it synchronizes with the PDF reader for seamless interaction.

With Emacs there is one problems. At some point you will have a temptation to use org-mode to write your papers. But, don't. You would just create an additional layer of abstraction that will hurt you long-term. Do not rely on other tools to generate code for you. Write it yourself. Do the work instead of improving the tools that will do the work for you.

Finally, make sure you use vertical monitor, even if you stick with overleaf.