How to create and compile LaTeX documents on Visual Studio Code
Tags: tex, latex, vscode, windows
Published: 2020-12-10 13:30:11

We all know that when it comes to typesetting lengthy documents, LaTeX is the answer. You only need to focus on content, and LaTeX will do the formatting for you. 

There are many online LaTeX compilers like *Overleaf* and offline editors like *TexStudio* but still, if you want to edit LaTeX documents on your favourite text editor (yes, it's everyone's favourite), this is how to do just that, on a Windows system.
<br>

## 1. Installing the TeX distribution (TeX Live)

**TeX Live** is a straightforward way to get up and running with the TeX document production. It includes all the major TeX-related programs and fonts including support for many languages around the world.

You can download TeX live installer here. 
[install-tl-windows.exe (ctan.org)](http://mirror.ctan.org/systems/texlive/tlnet/install-tl-windows.exe)

If the above link is not working go to this link and download install-tl-windows.exe
[Installing TeX Live over the Internet - TeX Users Group (tug.org)](https://www.tug.org/texlive/acquire-netinstall.html)
<br>
<img src="https://i.imgur.com/dUnb1Et.jpg" alt="Tex-Live download page">

Then "install" the program (not unpack) and wait for the packages to install.

Reboot after the installation is complete so it will reload the environment variables.


## 2. Setting up VS Code

To export LaTeX documents to PDFs, view PDFs, Intellisense and more features, we have to install an extension for VS Code. 

You can install the extension from the link below.

[LaTeX Workshop - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=James-Yu.latex-workshop&ssr=false#overview)

<img src = "https://i.imgur.com/14BxOu2.jpg" alt="LaTeX workshop">

For additional features you can install LaTeX utilities, but it is no longer maintained by the developer.

[LaTeX Utilities - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=tecosaur.latex-utilities)

All done! Now you have set up the environment for creating LaTeX documents.

Let's test our setup with a practice code.

Create and save file with a .tex extension on vscode. (eg: "mydocument.tex")
		


    \documentclass[12pt]{article}
    
    \usepackage{amsmath}
    
    \usepackage{graphicx}
    
    \usepackage{hyperref}
    
    \usepackage[utf8]{inputenc}
    
    \title{How to Set Up LaTeX on VSCode}
    
    \author{Mozilla Club of UCSC}
    
    \date{2020–12–10}
    
    \begin{document}
    
    \maketitle
    
    \section{Introduction}
    
    Here is the introduction of our text
    
    \begin{itemize}
    
    \item One
    
    \item Two
    
    \item Three
    
    \end{itemize}
    
    \end{document}

After saving the file, click on the magnifying glass icon on the top right corner.

<img src="https://miro.medium.com/max/700/1*j0SXoRve6omkoYWIa4RVmA.png" alt="Compile PDF button">

Now it should display the PDF view of your latex document on the right side of the VS Code window.
 
If it doesn't show up, click the TeX icon on the left horizontal menu, and click on "View LaTeX PDF" under the COMMANDS palette.

<img src="https://miro.medium.com/max/434/1*ZMovIB4H0TOkkBolnMrqGg.png" alt="Commands palette in vscode">
 
Compiled PDF document will now open with your default browser. 

That's it! Now you can create and export LaTeX documents on your favourite text editor. If you have any problem regarding the whole process please drop a comment below.