My LaTeX Setup - vim, Skim, and latexmk28 Jun 2018
I’ll describe my current LaTeX setup – vim, skim, and latexmk.
I currently write notes and papers using LaTeX on a Mac, though in a previous life, my setup on Linux was very similar (i.e.,
I like being able to use my own customized text editor (with my favorite keyboard shortcuts) to edit a raw text file that I can then put under version control.
Though I describe things with respect to vim, most of this setup can also
achieved with some other text editor, e.g., emacs or sublime.
The basic setup
Text editor: vim
PDF reader: Skim
For my pdf reader, I use the Skim app. The nice thing about Skim is that it will autoupdate the pdf after you compile the tex and keep the document in the same place. By contrast, Preview will refresh the document and reload it from the beginning of the document, which is quite cumbersome if you’d just edited text on page 5.
Compilation: latexmk + vim keybindings
In vim, I have several keybindings set up in my .vimrc file. Currently, I compile the .tex file using latexmk. Files can be compiled to pdf with the command
In latexmk, you can also automatically recompile the tex when needed, but I prefer to manually compile the tex.
I have the following key bindings in vim:
control-Tcompiles the tex to pdf using latexmk
shift-Topens the pdf in Skim
shift-Ccleans the directory
For instance, the compile keybinding above is done by adding the following line to the .vimrc file
These types of key bindings can usually be setup with other text editors as well.
Putting it all together
When I’m writing a document, I’ll often have my text editor full screen on the
left and the Skim on the right with the pdf open. After making edits, I’ll press
control-T to compile and the pdf will auto-refresh in Skim.
Example of macvim next to Skim setup. Monitor recommended :)
Tools for writing LaTeX documents
There are a few other tools that I use for writing papers (or extensive notes on work) that I’ll list below that save me a lot of time.
In vim, I have several plugins I have in my .vimrc file. For writing papers, I
use ()[snippets] extensively. My most used command is typing
begin <tab>, which
allows me to allows me to autocomplete the parts of LaTeX that I don’t want to
spend time typing but use often. For instance, in the TeX below, snippets means
I only have to type
And should I need to change
align* to just
align, I only have to
edit this in one of the parens instead of in both lines.
:PluginInstall while in command mode in vim.
For writing quick notes, I have a TeX skeleton file that always loads when I
start a new vim document, i.e., when executing
vim notes.tex in the
command line, a fully-functional tex skeleton with all the packages I normally use and font styles are
automatically loaded. E.g., a version of the following:
For longer documents, I use the subfiles package extensively. This allows me to split a document into smaller files, which can then be individually compiled into its own document. Subfiles inherit the packages, etc., that are defined in the main file in which the subfiles are inserted.
The advantage of using subfiles is that you can just edit the subfile you’re currently focusing on, which is much faster than compiling the entire document (especially one with many images and references). This also helps with reducing the number of git conflicts one encounters when collaborating on a document.
I have a set of macros that I commonly use that are imported when I load a .tex document. For writing papers, I’ll include a separate macros.tex file with all of my macro definitions that I reuse often. Some example macros I’ve defined:
Also super convenient if you’re defining a variable that is always bold if, for instance, that variable is a vector.
My collaborators and I often have a commenting file we use to add various comments (in different colors too!) in the margins, in the text, or highlighting certain regions of the text. An alternative is to use a LaTeX commenting package and then define custom commands controlling how the comments appear in the text.
You can check out my .vimrc file on github to see how I set up keybindings, plugins, and my .tex skeleton file.