How to set up VS Code for LaTeX

I am currently writing my Master’s thesis. On this occasion I set up one of my favorite IDEs to handle the LaTeX workload automatically. Read more about the TeX family.


NOTE

There are great alternative workflows that will not be covered in this article. You could also write your documents in markdown and use a converter like pandoc to build the TeX files. However, I wanted to stick to the LaTeX template from my university and avoid extra troubles.


How to set up Visual Studio Code

Required

Perl
is required for everything to run properly. At least according to a solution for a compilation error I encountered. So I installed Strawberry Perl for Windows.
LaTeX Workshop
provides core features for LaTeX typesetting. See the wiki for detailed description.

Formatting files with LaTeX Workshop resulted in an error. So I used the pre-installed CPAN client to install the missing perl module. Roughly following this explanation I simply opened CPAN and executed the following command:

install Log::Log4perl

Optional

Zen Mode
distraction free UI mode in VS Code. Hides activity bar, status bar, sidebar, panel, …
Todo Tree
highlights TODO, FIXME and other tags and shows them as a tree view. This extension comes from programming, but I found it to be useful for typesetting as well. Add "todo-tree.regex.regex": "((//|#|<!--|;|/\\*|^|%|\\\\)\\s*($TAGS)\\{*|^\\s*- \\[ \\])" to the settings.json in VS Code.
Spell Right
a lightweight, offline, multilingual spellchecker. If you are working with VS Code workspaces, you can even add words to the workspace dictionary.
Vscode Google Translate
quickly translates text inline. This way I got rid of my frequent “What was that word again?”-thoughts.

Shortcuts

File - Preferences - Keyboard Shortcuts

I set shortcuts for Toggle Zen Mode, Translate selection to preferred language and for some of my snippets (explained later).

The new workflow

  1. Execute the LaTeX Workshop Command View in VSCode tab.
  2. Enter Zen Mode via your shortcut.
  3. Edit the file and save. That’s it!

The setup automatically compiles the TeX files and updates the pdf view as soon as it is done.

Tips and tricks

  • Use Workspaces in VS Code to bundle settings, folders, and other important stuff for individual projects.
  • Use snippets! File - Preferences - User Snippets lets you create your own, do so per workspace! I added some for my figures (especially a snippet that uses the dummy image), variables, and environments that I use on a regular basis. Tab stops and multiple snippet variations are a great addition for flexibility.
  • Add a dummy image to your images folder. This will come in handy when you don’t have the correct image at hand or have to create an illustration but want to do this after writing.