While online clients like ShareLaTeX or writeLaTeX are popular for getting started with LaTeX quickly, developing LaTeX locally with Vim and the command line is my preferred LaTeX workflow. In this post, I’ll describe the changes I’ve made that make working with LaTeX on the command line a seamless experience.
Obviously, to work with LaTeX locally, you’ll need LaTeX installed. To check if
you already have it installed, you can run
which pdflatex. If it’s installed,
this command will tell you the path to program. Otherwise, it won’t print
Installing LaTeX on Linux isn’t too bad. Usually it’s included in your distribution’s package manager. I’ll be focusing on OS X for the majority of this post though, so Google around if you end up having trouble.
On OS X
To install LaTeX on a Mac, we’ll be installing MacTeX, which includes the
command line LaTeX utilities as well as a couple graphical clients for LaTeX
development. You can try compiling from source, but as Homebrew points out when
you try to
brew install latex:
With that in mind, head on over to
http://www.tug.org/mactex/ and download the file
MacTeX.pkg. Once this has downloaded and you’ve clicked through the
installer, you should be ready to go with LaTeX. Verify this by running
The biggest productivity improvement you gain from developing LaTeX locally is that you get to use Vim. Make sure you have a nice colorscheme for both your terminal and for Vim. I can’t stress enough how important it is to make your terminal look nice: you want to enjoy your terminal experience, and this is one of the easiest ways to do so.
Compiling LaTeX is pretty straightforward. To generate a PDF, all you have to do is run the command
and you’ll get a file called
<myfile>.pdf in the current directory, plus some
intermediate files. We can go one step further and put a bunch of useful build
targets into a Makefile and use it to build our PDF:
If you save this to a file called
Makefile in the same directory as your LaTeX
file, we can just run
make instead of running
As you can see, there are a bunch of other handy targets here:
make cleanwill remove all intermediate files that are created.
make verycleanwill remove all intermediate files and the compiled PDF file.
make viewwill compile the file and then open it up in a PDF viewer (if you’re on OS X, or on Linux and have
make printwill send your document to the default printer with the default options for that printer.
make submitwill copy your file into the parent directory. This is handy when you’re working in a subfolder on an assignment to isolate the intermediate files, but your class has provided a handin script that needs the PDF file to be in the parent directory.
Right now, our workflow looks like this:
- Create TeX file
- Edit in Vim
- Switch to terminal
- Run make view to compile and view
We can actually optimize this workflow to one less step: we don’t have to get out of Vim to run make!
Vim has a command
:make that will look for a Makefile in the current directory
and run it’s
all target. It also takes a target as an optional argument, so we
:make view to compile and view the document from within Vim!
Taking this one step further, we can add a command to shorten this. If we add
.vimrc, we’ll only have to type
:WV to save, compile, and view our
That’s it! I like this experience for a bunch of reasons:
- It’s faster. Compiling LaTeX without having to wait for a web client to load is really nice.
- It’s more stable. You can still edit, compile, and view your work if you don’t have access to the Internet.
- It’s faster. Using Vim to edit text is much more convenient than a standard text editor.
Do you have a LaTeX tip, a fancier Makefile, or a favorite vim plugin for LaTeX? Share it in the comments!
Actually that’s not it, there’s more! I wrote a Part 2 to this post, which you should definitely check out.