TeX Setup

Table of contents

How to get TeX up and running with UTF-8 on various systems, using XeLateX and VSCode.

example gif

What is this ?

This is a tutorial to get a TeX distribution running on Linux/Windows, with UTF-8 support, using the Visual Studio Code editor.

(This is also a personal reminder in case I need to do it all again 🙂)

Why UTF-8 ?

I find it way easier to write/read TeX documents this way: for me,

Hellö W⊕rld
$$ f: Xₙ → ℒ ∪ ℂ ∪ ∅ $$

Is way more readable than:

Hell\"{o} W$\oplus$rld
$$ f: X_n \to \mathcal{L} \cup \mathbb{C} \cup \emptyset $$

Also don't worry too much about portability: this setup works on Windows, Linux, and even (imperfectly) Overleaf (with the compiler set to XeLateX).

Why VSCode ?

Drawbacks

Dependencies

Be sure to install the dependencies for your system before continuing !

Visual Studio Code setup

Now that we have all we need, launch VSCode.

We will need a few things to get the TeX support we want:

Extensions

VSCode can be extended with third-party addons called extensions.

To install extensions, go to the extensions panel:

There, you can search and install extensions. Install the following extensions:

Settings

Now since we use xelatex instead of the more classic latex, we need to change some settings. Open the settings on the bottom-left:

You can modify the settings from here, but it will be easier to change the settings file directly. Click on the "Open Settings (JSON)" button on the top-right:

And replace the content of the file with

{
  // Use XeLateX instead of LateX
  "latex-workshop.latex.tools": [
    {
      "name": "latexmk",
      "command": "latexmk",
      "args": [
        "-xelatex",
        "-output-directory=build",
        "-synctex=1",
        "-interaction=nonstopmode",
        "-file-line-error",
        "%DOC%"
      ]
    }
  ],
  // Put the build artifacts in a 'build' directory next to the '.tex' file
  "latex-workshop.latex.outDir": "%DIR%/build",
  // View the resulting PDF in dark mode.
  "latex-workshop.view.pdf.invertMode.enabled": "always",
  "latex-workshop.view.pdf.invert": 0.9,
  // View the PDF directly in VSCode
  "latex-workshop.view.pdf.viewer": "tab"
}

(Remove the lines you don't want)

The LateX Workshop extension has various interesting settings, don't hesitate to play with these

Write some TeX !

Now we can start writing TeX !

Open a new directory in VSCode, and create a new main.tex file in it. Fill it with

\documentclass[a4paper]{article}

\usepackage{fontspec}
\usepackage{unicode-math}
\setmainfont[Ligatures=TeX]{FreeSerif}

\begin{document}

Hellö W⊕rld
$$ f: Xₙ → ℒ ∪ ℂ ∪ ∅ $$

\end{document}

You can then:

The resulting PDF (and intermediary files) can be found in the build directory next to main.tex.

Easily write UTF-8

Note the 2 extensions we installed after Latex Workshop: latex-input and Unicode Latex. These will help us write any character we want: