Real-time LaTeX Using (Neo)Vim
This tutorial series will help you set up the Vim or Neovim text editors for efficiently writing LaTeX documents. Here is an example of what I have in mind:
The middle blue bar shows the keys I am typing, the bottom shows the resulting LaTeX source code, and the top is the compiled output. More on how this works below.
Goal of this guide: make writing LaTeX as easy (fast, efficient, enjoyable…) as writing math by hand. Tech stack: the Vim text editor using the UltiSnips snippet plugin and the VimTeX plugin’s LaTeX editing features. The series should help if you…
- are interested in taking real-time lecture notes using LaTeX, à la Gilles Castel,
- want a LaTeX experience decidedly more pleasant and efficient than whatever you were probably first taught, whether your motivation is real-time university lecture speed or not,
- hope to switch to Vim from a different LaTeX editor, but are unsure how to proceed, or
- just want to browse someone else’s workflow and configuration out of curiosity.
What it costs you: everything in the guide is free, but it will cost you time and effort. You can skim through the guide in about 15 minutes; a closer read-through might take 45-60 minutes; and you’ll realistically need a few weekends (or perhaps a few weeks if you’re new to Vim) of focus and effort to become fully functional. From that point reaching the speed in this page’s GIFs would probably take a few months of practice.
Cover prerequisites for getting the most out of the series, along with references that should get you up to speed if needed.
Explain snippets, the key to real-time LaTeX.
Introduce Vim’s filetype plugin system, which will help you understand the VimTeX plugin.
Cover the excellent VimTeX plugin—the reason to use Vim over another LaTeX editor.
Show how to compile LaTeX documents from within Vim.
Integrate Vim and a PDF reader for viewing LaTeX documents.
A Vimscript primer explaining the key mappings and Vimscript functions used in this tutorial.
Shut up and show me results
As concrete evidence that the techniques in this tutorial work in practice, here are 1500+ pages of typeset physics notes from my undergraduate studies, most of them written during university lecture in real time (although grammar and style were improved later). Here are some examples of what these notes look like:
And here are more GIFs showing that LaTeX can be written at handwriting speed:
This is actually a little faster than I can write by hand—try taking out a pencil and paper and see if you can keep up! (Yes, I know I’m cheating by throwing in a bunch of hard-to-handwrite integrals.) If you like, you can see more examples on YouTube.
Credit where it is due: the above GIFs are inspired by Gilles Castel’s video Fast LaTeX editing with Vim and UltiSnips—it is beautifully done and I encourage you to watch it.
A human-friendly guide
The series is written with the voice, format, notation, and explanation style I would have liked to have read if I were once again an inexperienced undergraduate learning the material for the first time myself.
All of the small discoveries I inefficiently scraped together from official documentation, online tutorials, YouTube, Stack Overflow, Reddit, and other online forums are compiled here and (hopefully) synthesized into an easily-followed, self-contained work. I do my best to write clearly and concisely. References to official documentation appear throughout the guide, so you know where each technique comes from. I’ll show you practical tips and tricks I use in everyday, real-life writing. You’ll find plenty of examples and GIFs. I might even crack a joke or two. Basically, I’ll try to teach how I would like to be taught. Hope it’s helpful!
The original Vim-LaTeX article
By the way: the seminal work on the subject of Vim and LaTeX, and my inspiration for attempting and ultimately succeeding in writing real-time LaTeX using Vim, is Gilles Castel’s How I’m able to take notes in mathematics lectures using LaTeX and Vim. You’ve probably seen it on the Internet if you dabble in Vim or LaTeX circles, and you should definitely read it if you haven’t yet.
This series builds on Castel’s article by more thoroughly walking the reader through technical details of implementation (e.g. the details of setting up a PDF reader with forward and inverse search, how to use the VimTeX plugin, how to write Vimscript functions and key mappings, how Vim’s
ftplugin system works, how to manually compile LaTeX documents, and so on).
Since someone will probably be curious, here is an overview of the setup used in this series:
- Editor: Neovim
- Terminal: Alacritty
- Colorscheme: Nord
- Font: Source Code Pro in the terminal and Computer Modern on this website; at the time of writing, the fonts used on this website are available on this demo page.
- OS: Arch Linux as a daily driver; macOS for testing cross-platform functionality
- Window manager: i3 on Linux; Amethyst on macOS
- GIF recording and screen capture: Menyoki
github.com/ejmastnak/dotfiles, where you can find both my main Neovim config and a smaller Vim config for testing Vim-specific inverse search features for this series.
Feedback, suggestions, appreciation, criticisms, etc.
- If this series helped you, it will make my day to hear.
- If you suggest constructive ideas for improving the series, I will quite likely implement them, appreciate your input, and give you credit for your contributions. (Thank you to @subnut for catching mistakes in this document.)
- If you implement the setup in this series and show me the results, I will be very happy to see.
Feedback is welcome and appreciated.
You can reach me by email, in English, Spanish, or Slovene, at
firstname.lastname@example.org (or open an issue or pull request at
Have ideas for future projects?
If there is collective interest from readers of this guide, I would consider creating follow-up content expanding on this series. Here are two possible projects:
- A GitHub repo implementing a minimum working example of the setup in this series (I’m thinking a minimal
vimrc, a few example UltiSnips snippets to get you started writing your own, basic VimTeX configuration etc.). This might be less overwhelming for new users than browsing my above-linked dotfiles.
- A write-up of how the GIFs in this series were made (using shell scripts for repeatable results and dimensions, setting colorscheme and fonts, reaching an acceptable resolution, etc.).
If these or other ideas interest you, let me know—if there is enough interest from the community, I’d enjoy putting together more content like this.
The original writing, images, and animations in this series are licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.