Use VSCode for LaTeX

Visual Studio Code (VSCode) is a free and open-source editor available for Windows, Linux, and macOS. I currently use VSCode for coding in Python, taking notes in markdown, and also editing this blog. I like VSCode because of the open-source extensions that you can use to tailor-make workspaces for the development context. In this post, I share a method to give VSCode Overleaf-like capabilities. It requires some time investment, but you can get many paid features of Overleaf for free.

Prepare your system

I am using Ubuntu 18.04 that runs on my Windows 10 PC with the Windows Subsystem for Linux 2 (WSL 2). If you also use Windows 10, I recommend using the following resources to set up WSL 2:

For a quick start, we will use the VSCode “Remote Containers” extension. It requires Docker installed on your system. You can follow the suitable instructions here to set up Docker on your operating system.

Set up Visual Studio Code

Download and install the latest stable version of VSCode. Opening the editor, VSCode detected that I have WSL installed, and suggested installing the recommended Remote - WSL extension. If you also have WSL installed, I recommend installing this extension.

VSCode suggests installing Remote - WSL extension after it detects it is installed on your system.

You also need the Remote Containers extension. Hit Ctrl+Shift+X to bring up the extensions panel. Search for and install the “Remote Containers” extension.

Prepare a development container for LaTeX

I prepared a git repo that contains the VSCode container configuration files for LaTeX. Download or clone the repo, and open the folder in VSCode editor. VSCode detects the configuration files and suggests reopening the folder to develop in a container. You can also hit F1 and type: Remote Containers: Reopen in Container. The container setup takes a long time, but it happens only once.

VSCode detects the configuration files and suggests reopening the folder in a container.

When the setup is complete, hit Ctrl+Shift+X and bring up the extensions panel. You will see the LaTeX Workshop installed but disabled. Enable the extension in the development container. VSCode may require a reload to enable the extension.

You need to enable LaTeX Workshop extension manually.

Start building LaTeX!

To start off, let’s use the IEEE’s LaTeX Template for conference proceedings. Go to the IEEE conference templates site and download the LaTeX Template (ZIP archive). Extract the zip archive to your development folder.

Folder structure in my development folder

Through explorer panel (Ctrl+Shift+E), find and open the *.tex file. Use Ctrl+Alt+V to view the LaTeX PDF file. That’s it! You now have a workspace that builds LaTeX and shows you the output PDF in real-time, similar to Overleaf. Check out LaTeX-Workshop’s GitHub Repo for the list of features and wiki.

Changes are reflected to theoutput PDF after you save the ``.tex`` document.

Insert citations and bibliography

Zotero is an open-source tool that helps you organize and cite your research. If you are not using any reference manager software, I highly recommend Zotero.

We need to install the Better BibTeX extension to Zotero. Use these steps to install the extension.

The extension generates citation keys in Zotero.

After installation, open Zotero, click “File > Export Library”. The format is Better BibTex, and you should check the keep updated option. Export the library to the development folder. I’ve named it zotero-library.bib.

To insert a bibliography, add the following lines at the end of your document. If you are still using the IEEE’s template, you need to remove the existing bibliography and citations in the text to prevent errors.

...

\bibliographystyle{ieeetr}

\bibliography{../zotero-library.bib}

\end{document}

You can now cite a key from your library using \cite{citationKeyInZoteroLibrary}.