Over the years, I wrote several hundred pages in LaTeX. That takes a lot of time and in order to use it efficiently, you need a good environment for LaTeX development. I tried many different tools in my search for a stack that works on multiple platforms (I develop on Linux and OS X) and minimizes distractions from the content, which is what really matters. This is the setup I have today.
Having a flexible editor that you feel comfortable with is important. Being a software developer, my ideal solution would be an IDE I’m used to from my day-to-day development, such as IntelliJ IDEA or NetBeans. While (La)TeX plugins exist for both IntelliJ IDEA and NetBeans, they’re not very good. Their development is also not very active, which can cause problems when updating your IDE, and that’s just the kind of problems I don’t want to deal with.
The best LaTeX editor I could find is TeXstudio. It’s cross-platform (Windows, Unix/Linux, BSD and OS X), open-source (GPL v2), and reasonably convenient to use. The feature I like the most is the keyboard shortcuts – TeXstudio comes with a sensible set of defaults not too different from major Java IDEs, and allows for customization of many shortcuts as well. It’s not perfect, but it lets you set up the editor to resemble IntelliJ IDEA well enough. TeXstudio also bundles a standard spellchecker as well as basic syntax highlighting and autocompletion. Menu for basic formatiing can be handy if you’re new to LaTeX or coming back to it after a while as well.
TeXstudio has a pretty decent build system, which supports multiple compilers and all the LaTeX tricks (index, bibliography etc.), including performing multiple runs when needed. Having said that, building from the editor can be a bit cumbersome and information sometimes gets lost. I’m also a fan of automatic compilation, without having to trigger it with a specific key. I don’t typically use TeXstudio to build my documents and get by with a simple shell script instead.
The script contains the following one-liner (also available as a gist on GitHub):
The first part of the script finds LaTeX files in the current directory that need to be built (
grep to output file names containing matches). The second part of the script calls Latexmk on the files from the first part.
Latexmk is a handy utility capable of watching files and building them whenever they change, which allows you to view the latest state of your document whenever you save your changes. The tool is smart – it automatically runs all the necessary commands and performs the build multiple times, if needed.
By default, Latexmk generates a .dvi file. The
-pvc stands for preview continuously, and that’s the option that makes the magic happen. It instructs Latexmk to run continuously and update the output document whenever it detects a change in the source files.
-silent, as you would expect, causes the programs to be run quietly, reducing the number of diagnostic messages.
Although my script doesn’t utilize any other Latexmk options, there’s a number of them worth investigating. A particularly interesting one is
-pdflatex, which specifies the command to run pdflatex. You typically use it to add pdflatex options, which allows you to e.g. add SyncTeX via
SyncTeX is a tool for synchronizing the source document and the PDF output. With the right editor and viever, such as TeXstudio, you can click in the PDF and jump to the appropriate place in the source document or vice versa. This nicely complements Latexmk’s watching capabilities. Together, they allow you to see the right place in the latest version of your document.
Note that you can also set up Latexmk with TeXStudio, if you don’t like having an external script.
While TeXstudio comes with an integrated PDF viewer, I prefer to use an external viewer richer in features, which I typically use either in a split-screen view with the editor, or in a full-screen view on a separate virtual desktop which I can quickly switch to, depending on the size and the nature of the document I’m editing. In order to take advantage of the script described in the previous section, you need a viewer capable of autoreloading the PDF and maintaining the scrolling position when the underlying file is regenerated.
My favourite application meeting this requirements on OS X is Skim. I use Okular on Linux.
Creating LaTeX documents is not unlike writing code in a programming language, but is rarely treated the same. It should be, and version control is no exception.
Like my code, I always keep my LaTeX projects in Git, typically on GitHub or GitLab. GitHub (GitLab) make it easy to collaborate and updates to a document made through pull (merge) requests are easy to track, review, and incorporate. Even when I’m the only person working on a document, I use Git to have a reliable backup of my work, and an easy way to undo changes. It’s important to apply standard software engineering practices, such as using proper commit messages. TeX tools generate a lot of auxiliary files, so don’t forget to use a sensible .gitignore to keep your repository clean.